Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Example steps for question 4:

2. console.log number.

3. Declare another variable roundedNumber that has the value of z but rounded to the nearest integer.
3. Declare another variable roundedNumber that has the value of number but rounded to the nearest integer.

4. console.log number.

Expand Down
108 changes: 108 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*1-Write a console.log statement saying "Hello World!" for each language that you know.*/
console.log('Halo, dunia!'); //Indoniasia
console.log('Ciao, mondo!'); //Italian
console.log('Hola, mundo!'); //Spanish

//2-onsider the following code://
console.log("I'm awesome");
//Declare a variable age and initialize it with an integer, using these exact steps://
var age;
console.log('The Value of Age will be: undefined');
console.log(age);
age= 28;
console.log('The Value of Age will be: 28');
console.log(age);
//4-Declare a variable name and assign a string to it.//
var name = 'Hamam Alsamel';
console.log('The Name will be: Hamam Alsamel');
console.log(name);
var x= name;
console.log('The Value of X will be: Hamam Alsamel');
console.log(x);
//5-How do you round the number 7.25, to the nearest integer (i.e., whole number)?
var number= 7.25;
console.log(number);
var z= 7;
console.log(z);
if (number>=z){
console.log(number);
var newvalue = number;
console.log(newvalue);
}
//6- Arrays//

const list = ['','',''];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The array here isn't empty - it does have values even though they're empty strings.
An empty array would be const list = [];

console.log('The array has no value becauswe its empty');
console.log(list);

const favouritanimal = ['Cat','Dog','Birds','elephant'];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the instructions said to use a plural name for your array since it contains a list of items, so a better name would be favouriteAnimals

console.log(favouritanimal);
favouritanimal.push('Kitten')
console.log(favouritanimal);

//7-More strings: Let's consider the following string: let myString = "this is a test".
let mystring= "This is a test";
console.log(mystring);
console.log(mystring.length);
console.log('the length of my string');

//8.If x equals 7, and the only other statement is x = x % 3, what would be the new value of x?

var x=7;
x = x%7;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused about what you're testing in this question! note that this should be x = x % 3, not x = x % 7

console.log(x);
console.log( x % 7);
if (x%7===0){
console.log("True");
}
else {
console.log('False');
}

//9.Write a program to answer the following questions:
const arrays=['tomate', 5, 'botato'];
console.log(arrays);

var x=6;
var y=10;
if (x/0===y/0) {
console.log('Infinities');
}

//10.I’ve declared a multidimensional array (an array inside an array) -- see below. How can I access the third item’s second element? i.e. [2, 1] is the third element, and I want to access 1. Add a console.log statement accessing this item.

const grid= [[0,1], [1,1], [2,1], [3,1]];
const item= grid[2,2];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn't cover this in class, but when working with nested arrays (arrays inside arrays), you need to use two sets of square brackets to access the element like grid[2][1].

For example, if you use grid[2], you get the second element of the grid array [2, 1]. So if you use grid[2][1], you get the second element of grid[2], which is 1.

grid[2]; // this is [2, 1]
grid[2][1]; // this is 1

I see why you'd use a comma like in [2, 2]! But that actually prints out [2, 1] instead of 1. I didn't understand why until I realized the comma operator returns the last value, so grid[2,2] becomes [2] (explanation)

console.log(item[1]);

//11.If I have a variable counter, and I want to increment it by 2, what are three ways I can do this? Add three console.log statements with the three different ways.

let counter =0;
console.log('First Method');
counter=counter+2;
console.log(counter);
console.log('Second Method');
counter+=2;
console.log(counter);
console.log('Third Method');
counter++;
counter++;
console.log(counter);

//12.12. Here’s a profile about a cat for adoption. Create variables to hold information about this cat as shown on the profile. For example:

const namee = 'Prince';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you declared name and age above so you can't redeclare them again, but I think catName and catAge would be better names to use in this case

const bestFriend = 'Thomas';
const breed = 'Domestic shorthair';
const color = 'Orange or red taby';
const agee ='One Year Old';
const sex ='Male'
const hair = 'Short';
const petID= ' ';

//13. Create two variables -- one to hold the names of the kittens and one to hold the names of the adult cats. Make sure to choose an appropriate data type to hold this information!

const kitten=['Kyle Meowry', 'Luna', 'Obi', 'Charlie', 'Raspheries'];
const adultcats= ['Mezzo', 'Sabrina', 'Josie'];
console.log(kitten);
console.log(adultcats);