Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 4a1b2b7

Browse files
authored
Hani's homework of javascript-week1
1 parent 96a78c2 commit 4a1b2b7

File tree

10 files changed

+194
-0
lines changed

10 files changed

+194
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
//Exercise 1: Hello world!
4+
5+
console.log('hallo,', 'wereld!'); //Nederlands
6+
console.log('Hallo,', 'Welt!'); //german
7+
console.log('Ciao,', 'mondo!'); // Italian
8+
console.log('Hola,', 'mundo!'); // Spanish
9+
console.log('Olá,', ' Mundo!'); //Portugal
10+
console.log("Selam,", "Dünya!"); //Turkia
11+
console.log('Halo,', 'dunia!'); // Indonesian
12+
console.log('Bonjour,', 'le monde!'); //Bonjour le monde franca
13+
console.log('Hai,', 'dunia!'); //Malay
14+
console.log('Kia,', 'ora!'); //Maori
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
//Exercise 10: Compare arrays
4+
5+
6+
const array1 = ['aaa', '333', false, { color: "blue" }];
7+
const array2 = ['up', 'down', 'right', 'left', 'forward', 'behind', 'middle'];
8+
console.log('the length of array1 is '+ array1.length);
9+
console.log('the length of array1 is '+ array2.length);
10+
if (array1.length == array2.length) {
11+
console.log('They are the same!')
12+
} else {
13+
console.log("Two different sizes!");
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
//Exercise 2: Error debugging
4+
5+
console.log("I'm awesome");
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
//Exercise 3: Log the number
4+
5+
let numberX; //step1
6+
console.log("x is a variable can be any number ") //step2
7+
console.log("I will give x the value 5") //step3
8+
numberX = 5; //step4
9+
console.log("I think the value must be 5 now (:") //step5
10+
console.log(numberX) //step6
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict'
2+
3+
//Exercise 4: Log the string
4+
5+
//1-Write a console.log statement in which you explain in words what you think the value of the string is.
6+
let myString = "Hani Badran";
7+
8+
//2-Write a console.log statement in which you explain in words what you think the value of the string is.
9+
console.log("This is my name");
10+
11+
//3-Now "console.log" the variable 'myString'.
12+
console.log(myString);
13+
14+
//4-Now reassign to the variable 'myString' a new string.
15+
myString = "Amsterdam"
16+
17+
//5-Just like what you did before write a console.log statement that explains in words what you think will be logged to the console.
18+
console.log('and this is my favorite city');
19+
20+
//6-Now console.log myString again.
21+
console.log(myString);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict'
2+
3+
//Exercise 5: Round a number and log it
4+
5+
//1-Declare a variable 'z' and assign the number 7.25 to it.
6+
const z = 7.25;
7+
8+
//2-Write a 'console.log' statement in which you log the value of 'z'.
9+
console.log(z);
10+
11+
//3-Declare another variable 'a' that has the value of 'z' but rounded to the nearest integer.
12+
const a = 7;
13+
14+
//4-Write a 'console.log' statement in which you log the value of 'a'.
15+
console.log(a);
16+
17+
//5-So now we have 'z' and 'a' find a way to compare the two values and store the highest of the two in a new variable.
18+
19+
const highest = a > z ? a : z;
20+
21+
//6-Write a console.log statement in which you log the value of the highest value.
22+
console.log(highest);
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict'
2+
3+
//Exercise 6: Log an array of animals
4+
5+
//1-Declare variable and assign to it an empty array. Make sure that the name of the variable indicates it contains more than 1 item. For example 'items' instead of 'item'.
6+
let colors = [];
7+
8+
//2-Write a 'console.log' statement that explains in words what you think the value of the array is.
9+
console.log('this is the basic colors');
10+
11+
//3-Write a 'console.log' statement that logs the array.
12+
console.log('["red", "green", "blue"]');
13+
14+
//4-Create a new variable with an array that has 3 of your favorite animals, each in a different string. Make sure the name of the variables says something about what the variable contains.
15+
const animals = ['cats', 'dogs', 'horses'];
16+
17+
//5-Write a 'console.log' statement that logs the second array.
18+
console.log(animals);
19+
20+
//6-Add a statement that adds another string ("Piglet") to the array of animals.
21+
animals.push('Piglet');
22+
23+
//7-Write a 'console.log' statement that logs the second array!
24+
console.log(animals);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
//Exercise 7: Log the length of a string
4+
5+
//1-Declare a variable called 'mySentence' and initialize it with the following string: "Programming is so interesting!".
6+
const mySentence = 'Programming is so interesting!';
7+
8+
//2-Figure out (using Google) how to get the len-gth of mySentence.
9+
const length = mySentence.length;
10+
11+
//3-Write a console.log statement to log the length of mySentence.
12+
console.log(length);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
//Exercise 8: Type checker
4+
5+
const str1 = 'aaa';
6+
const str2 = 'bbb';
7+
const obj1 = ['ccc', 'ddd'];
8+
const obj2 = ['eee', 'fff'];
9+
if (typeof str1 == typeof str2) {
10+
console.log('SAME TYPE');
11+
} else {
12+
console.log('not the SAME...');
13+
}
14+
15+
if (typeof str1 == typeof obj1) {
16+
console.log('SAME TYPE');
17+
} else {
18+
console.log('not the SAME...');
19+
}
20+
21+
if (typeof str1 == typeof obj2) {
22+
console.log('SAME TYPE');
23+
} else {
24+
console.log('not the SAME...');
25+
}
26+
27+
if (typeof str2 == typeof obj1) {
28+
console.log('SAME TYPE');
29+
} else {
30+
console.log('not the SAME...');
31+
}
32+
33+
if (typeof str2 == typeof obj2) {
34+
console.log('SAME TYPE');
35+
} else {
36+
console.log('not the SAME...');
37+
}
38+
if (typeof str2 == typeof str1) {
39+
console.log('SAME TYPE');
40+
} else {
41+
console.log('not the SAME...');
42+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
//Exercise 9: Log the remainder
4+
5+
//Computers use a format that cannot accurately represent a number like '0.1' or '0.3' .The '0.1' is rounded to the nearest number in that format even before the calculation happens.
6+
7+
//if x equals 7, and the only other statement is x = x % 3, the value of x after the calculation will be 1.
8+
let x = 7;
9+
x %= 3 ;
10+
console.log(x);
11+
12+
//if y equals 21, and the only other statement is y = y % 4, the value of x after the calculation will be 1.
13+
let y = 21;
14+
y %= 4;
15+
console.log(y);
16+
17+
//if z equals 13, and the only other statement is z = z % 2, the value of x after the calculation will be 1.
18+
let z = 13;
19+
z %= 2;
20+
console.log(z);

0 commit comments

Comments
 (0)