diff --git a/Week2/10_program.js b/Week2/10_program.js new file mode 100644 index 000000000..55015db07 --- /dev/null +++ b/Week2/10_program.js @@ -0,0 +1,14 @@ +// 10.1 Can you store multiple types in an array? Numbers and strings? Make an example that illustrates your answer. + +let myArray = ["My age", 30, ["Student", 5]]; // With array is possibale to store different data, within a single variable +console.log(myArray); + + +//10.2 Can you compare infinities? (Not in Eyad's world) - does 6/0 === 10/0? How can you test this? +//10.3 Add console.log statements to the above program +let inf1 = 10 / 0; +let inf2 = 6 / 0; + +if (inf2 === inf2) + console.log("inf1 and inf2 are infinity") +else console.log("False") diff --git a/Week2/1_hello_world.js b/Week2/1_hello_world.js new file mode 100644 index 000000000..1a84d90dd --- /dev/null +++ b/Week2/1_hello_world.js @@ -0,0 +1,8 @@ +console.log("Hallo Wereld"); // Dutch +console.log("Bonjour le monde"); // French +console.log("مرحبا بالعالم"); // Arabic +console.log("ہیلو دنیا"); // Urdu +console.log("Selam Dünya"); // Turkish +console.log("你好,世界"); // Chinese +console.log("Hallo Welt"); // German + diff --git a/Week2/2_SyntaxError.js b/Week2/2_SyntaxError.js new file mode 100644 index 000000000..69ab07f9b --- /dev/null +++ b/Week2/2_SyntaxError.js @@ -0,0 +1,8 @@ +console.log('I\'m awesome') + // Error type: SyntaxError: missing ) after argument list } + + // Reason : here is no "+" operator to concatenate the string + // so JavaScript expects the argument for the log function to be just 'I'. + // In that case, it should be terminated by a closing parenthesis. + + // Solution : Adding backslash (\) after 'I diff --git a/Week2/3_declaring.js b/Week2/3_declaring.js new file mode 100644 index 000000000..a27dce9d6 --- /dev/null +++ b/Week2/3_declaring.js @@ -0,0 +1,6 @@ +let x; //declare the variable +console.log("My variable x will be my age");// what supposed x to be +console.log(x) // here will get an undefined result because the x was not initialized yet +x=30; // now we have assigned x to an integer +console.log("My variable x will be my age"); +console.log(x); // here we get definded result \ No newline at end of file diff --git a/Week2/4_assign_string.js b/Week2/4_assign_string.js new file mode 100644 index 000000000..3f8c358c9 --- /dev/null +++ b/Week2/4_assign_string.js @@ -0,0 +1,6 @@ +let y="Mosleh"; //Declare a variable y and assign a string to it. +console.log("My variable y will be my name");// what supposed y to be +console.log(y); // prent actula value of y +y="football"; // Re-assigning y to a different value +console.log("My new variable y will be my hobby")// what new value of y will be +console.log(y); // get new result of y \ No newline at end of file diff --git a/Week2/5_round_numbder.js b/Week2/5_round_numbder.js new file mode 100644 index 000000000..bd171351a --- /dev/null +++ b/Week2/5_round_numbder.js @@ -0,0 +1,6 @@ +const z = 7.25; +console.log(z); +let a = Math.round(z); +console.log(a); +let biggerNum = Math.max(a,z); +console.log(biggerNum); diff --git a/Week2/6_arry.js b/Week2/6_arry.js new file mode 100644 index 000000000..58588ef03 --- /dev/null +++ b/Week2/6_arry.js @@ -0,0 +1,8 @@ +let zoo=[]; +console.log("The value of the array will be []"); +console.log(zoo); +zoo=['Lione', 'Tiger', 'Giraffe', 'Elephant']; +console.log(zoo); +zoo.push('baby pig'); +console.log(zoo); + diff --git a/Week2/7_string.js b/Week2/7_string.js new file mode 100644 index 000000000..2dface101 --- /dev/null +++ b/Week2/7_string.js @@ -0,0 +1,2 @@ +let myString = "this is a test"; +console.log('the length of myString is'+' '+ myString.length); \ No newline at end of file diff --git a/Week2/8_checkTypeOfData.js b/Week2/8_checkTypeOfData.js new file mode 100644 index 000000000..d164ed0dd --- /dev/null +++ b/Week2/8_checkTypeOfData.js @@ -0,0 +1,33 @@ +// 8.1 First declare at least four variables and assign them different data types +let num = 5; +let str = "name"; +let arr = ["blue", "black", "Red"]; +let boo = false; + +// 8.2 For each variable write a console.log statement that logs the value +// 8.3 Now write a console.log statement wherein you first explain in words what you think the type of your variables is. +// 8.4 Now use typeof to log the actual type of your variables. +console.log("The value of my variable 'num' is: " + num); +console.log("num is: Number"); +console.log("The value of my variable 'str' is: " + str); +console.log("str is: String"); +console.log("The value of my variable 'arr' is: " + arr); +console.log("arr is: Array"); +console.log("The value of my variable 'boo' is: " + boo); +console.log("boo is: Boolean"); + +//8.5 Now compare the types of your different variables with one another. +//8.6 Make sure to also show a message when the variables you are comparing are not the same type. +function compareType(var1,var2) { + if (typeof var1 == typeof var2) { + console.log( "this variable have the same type"); + } else { + console.log("The first variable assigned to %o and the second variable assigned to %o ",typeof var1 , typeof var2 ); + } +} +compareType(num,str); +compareType(num,arr); +compareType(num,boo); +compareType(str,arr); +compareType(str,boo); +compareType(arr,boo); diff --git a/Week2/9_reminder.js b/Week2/9_reminder.js new file mode 100644 index 000000000..ee79f119c --- /dev/null +++ b/Week2/9_reminder.js @@ -0,0 +1,13 @@ +let X = 7; +X = X % 3; +console.log(X); ("The new value of X will be the reminder of divides a X by 3 which is 1") + +let value1 = 5; +value1 = value1 % 2; +console.log(value1); // The result will be 1 +let value2 = 8; +value2 = value2 % 3; +console.log(value2); // The result will be 2 +let value3 = 9; +value3 = value3 % 3; +console.log(value3); // The result will be 0 \ No newline at end of file diff --git a/Week2/index.html b/Week2/index.html new file mode 100644 index 000000000..206fe3207 --- /dev/null +++ b/Week2/index.html @@ -0,0 +1,24 @@ + + + +
+ + +