diff --git a/task1.js b/task1.js new file mode 100644 index 000000000..8807063b8 --- /dev/null +++ b/task1.js @@ -0,0 +1,12 @@ +//1 write a console.log statement saying "Hello World!" for each language that you know. + +let EnglishGreeting = "Hello world!"; +console.log (EnglishGreeting) +let ArabicGreeting = "مرحباً بالعالم"; +console.log (ArabicGreeting) +let ItalianGreeting = "Ciao Mondo!"; +console.log (ItalianGreeting) +let TurkishGreeting = "Selam Dünya!"; +console.log (TurkishGreeting) +let DutchGreeting = "Hallo Wereld!"; +console.log (DutchGreeting); \ No newline at end of file diff --git a/task10.js b/task10.js new file mode 100644 index 000000000..a7746e78e --- /dev/null +++ b/task10.js @@ -0,0 +1,14 @@ +/* 10. Write a program to answer the following questions: +10.1 Can you store multiple types in an array? Numbers and strings? Make an example that illustrates your answer. +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 in which you show that you understand the concepts (just like you've done in the above assignments).*/ + +let multipleTypesArray = ['class', 21 , true]; +console.log(typeof(multipleTypesArray[0])); +console.log(typeof(multipleTypesArray[1])); +console.log(typeof(multipleTypesArray[2])); + +//10.2 +let x1 = 6/0; +let y1 = 10/0; +x1 === y1? console.log('Yes') : console.log('No'); diff --git a/task2.js b/task2.js new file mode 100644 index 000000000..58df526ed --- /dev/null +++ b/task2.js @@ -0,0 +1,7 @@ +/*2 cosider the following code: console.log('I'm awesome'); +copy the code in your .js file and run it. +you will see that you get a syntaxError. +find a solution for this error. +Hint:read the error message carefully, it also gives an indication of where the problem is.*/ + +console.log ('I\'m awesome'); \ No newline at end of file diff --git a/task3.js b/task3.js new file mode 100644 index 000000000..d8de3fe05 --- /dev/null +++ b/task3.js @@ -0,0 +1,19 @@ +//3 Declare a variable x and initialize it with an integer, using these steps: +//3.1 First, Declare your variable x (do not initialize it yet) +//3.2 add a console.log statement that explains in words what you think the value of x is. +//3.3 add a console.log statement that logs the value of x. +//3.4 Now initialize your variable x with an integer. +//3.5 Next, add console.log statement that explains what you think the value of x is. +//3.6 add a console log staement that logs the value of x. + +let x ; + +console.log ("the value of my variable x will be:an Integer"); + +console.log (x); + +x = 8 ; + +console.log ("the value of my variable x will be:an Integer"); + +console.log (x); \ No newline at end of file diff --git a/task4.js b/task4.js new file mode 100644 index 000000000..3023b7057 --- /dev/null +++ b/task4.js @@ -0,0 +1,23 @@ +//4 Declare a variable y and assign a string to it. +//4.1 Write a console.log statement in which you explain in words what you think the value of the string is. +//4.2 Now console.log the variable y. +//4.3 Now assign a new string to the variable y. +//4.4 Write a console.log statement that explains in words what you think will be logged to the console. +//Now console.lg y again + +let y = "HackYourFuture"; + + +console.log ("the value of the string is: " + "HackYourFuture"); + + +console.log (y); + + +y = "HYF"; + + +console.log ("the value of the string is: " + "HYF"); + + +console.log (y); diff --git a/task5.js b/task5.js new file mode 100644 index 000000000..16ecdd900 --- /dev/null +++ b/task5.js @@ -0,0 +1,27 @@ +//5 How do you round the number 7.25 to the nearest integer, +//5.1 Declare a variable z and assign the number 7.25 to it. +//5.2 Console.log z. +//5.3 Declare another variable a that has the value of z but rounded to the nearest integer. +//5.4 console.log a. +//5.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. +//5.6 console.log the highest value. + +let z = 7.25; + +console.log(z); + +let a = (Math.round(z)); + +console.log(a); + +let highest; +if (z > a) { + highest = z ; +} +else { + highest = a ; +}; + +console.log(highest); + +//You can also use math.max, but this solution is fine \ No newline at end of file diff --git a/task6.js b/task6.js new file mode 100644 index 000000000..bca72b897 --- /dev/null +++ b/task6.js @@ -0,0 +1,16 @@ +//6 +let favoriteAnimals = [ ]; + +console.log("the value of my array is : Empty."); + +console.log(favoriteAnimals); + +let myFavoriteAnimals = [ 'Deer' , 'Horse' , 'Koala' ]; + +console.log (myFavoriteAnimals); + +let newMyFavoriteAnimals = myFavoriteAnimals.concat(['baby pig']); + +console.log (newMyFavoriteAnimals); + +// you can also use myFavoriteAnimals.push('baby pig'); Which might be an easier solution. diff --git a/task7.js b/task7.js new file mode 100644 index 000000000..ef7d1509d --- /dev/null +++ b/task7.js @@ -0,0 +1,9 @@ +/* 7. More strings +Let's consider the following string: let myString = "this is a test". +7.1 Add the string to your file and console.log it. +7.2 Find a way to get the length of myString. +7.3 console.log the length of myString.*/ + +let myString = "this is a test"; +console.log(myString); +console.log(myString.length); diff --git a/task8.js b/task8.js new file mode 100644 index 000000000..ff7e61cf4 --- /dev/null +++ b/task8.js @@ -0,0 +1,65 @@ +/* 8. Write a program that checks the types of two variables and prints out SAME TYPE if they are the same type. +8.1 First declare at least four variables and assign them different data types. +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. +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.*/ + + +let type1 = 21 ; +console.log ("The value of my variable type1 is: " + type1); +console.log (typeof(type1)); +let type2 = ['HTML', 'CSS'] ; +console.log ("The value of my variable type2 is: " + type2); +console.log (typeof(type2)); +let type3 = " Hello JavaScript " ; +console.log ("The value of my variable type3 is: " + type3); +console.log (typeof(type3)); +let type4 = "Class21" ; +console.log ("The value of my variable type4 is: " + type4); +console.log (typeof(type4)); + +//8.5 +if (typeof(type1)===typeof(type2)) { + console.log('type1 and type2 are SameType'); +} +else { + console.log('type1 and type2 are NOT SameType'); +} + +if (typeof(type1)===typeof(type3)) { + console.log('type1 and type3 are SameType'); +} +else { + console.log('type1 and type3 are NOT SameType'); +} + +if (typeof(type1)===typeof(type4)) { + console.log('type1 and type4 are SameType'); +} +else { + console.log('type1 and type4 are NOT SameType'); +} + +if (typeof(type2)===typeof(type3)) { + console.log('type2 and type3 are SameType'); +} +else { + console.log('type2 and type3 are NOT SameType'); +} + +if (typeof(type2)===typeof(type4)) { + console.log('type2 and type4 are SameType'); +} +else { + console.log('type2 and type4 are NOT SameType'); +} + +if (typeof(type3)===typeof(type4)) { + console.log('type3 and type4 are SameType'); +} +else { + console.log('type3 and type4 are NOT SameType'); +} + diff --git a/task9.js b/task9.js new file mode 100644 index 000000000..d88334482 --- /dev/null +++ b/task9.js @@ -0,0 +1,8 @@ +/* 9. If x equals 7, and the only other statement is x = x % 3, what would be the new value of x? +9.1 Add at least 3 console.log statements in which you show that you understand what % does.*/ + +let x = 7 ; +x = x % 3; +console.log(x = x % 3); +console.log(x %= 3); +console.log(x); diff --git a/week2homework.js b/week2homework.js new file mode 100644 index 000000000..7d2335311 --- /dev/null +++ b/week2homework.js @@ -0,0 +1,121 @@ +//1 +let EnglishGreeting = "Hello world!"; +console.log (EnglishGreeting) +let ArabicGreeting = "مرحباً بالعالم"; +console.log (ArabicGreeting) +let ItalianGreeting = "Ciao Mondo!"; +console.log (ItalianGreeting) +let TurkishGreeting = "Selam Dünya!"; +console.log (TurkishGreeting) +let DutchGreeting = "Hallo Wereld!"; +console.log (DutchGreeting) + +//2 +console.log ('I\'m awesome'); + +//3 +let x ; +console.log ("the value of my variable x will be:EvenNumber"); +console.log (x); +x = 8 ; +console.log ("the value of my variable x will be:EvenNumber"); +console.log (x) + +//4 +let y = "HackYourFuture" +console.log ("the value of the string is "+"HackYourFuture") +console.log (y) +y = "HYF" +console.log ("the value of the string is "+"HYF") +console.log (y) + +//5 +let z = 7.25; +console.log(z); +let a = (Math.round(z)); +console.log(a); + +let highest; +if (z>a){ + highest=z; +} +else{ + highest=a; +} +console.log(highest); + + +//6 +let FavoriteAnimals = [ ]; //6.1 +console.log("the value of my array is : Empty."); //6.2 +console.log(FavoriteAnimals); //6.3 +let MyFavoriteAnimals = [ 'Deer' , 'Horse' , 'Koala' ]; //6.4 +console.log (MyFavoriteAnimals); //6.5 +let NewMyFavoriteAnimals = MyFavoriteAnimals.concat(['baby pig']); //6.6 +console.log (NewMyFavoriteAnimals); //6.7 + +//7 +let myString = "this is a test"; +console.log(myString); +console.log(myString.length); + +//8 +let type1 = 21 ; +console.log ("The value of my variable type1 is: " + type1); +console.log (typeof(type1)); +let type2 = ['HTML', 'CSS'] ; +console.log ("The value of my variable type2 is: " + type2); +console.log (typeof(type2)); +let type3 = " Hello JavaScript " ; +console.log ("The value of my variable type3 is: " + type3); +console.log (typeof(type3)); +let type4 = "Class21" ; +console.log ("The value of my variable type4 is: " + type4); +console.log (typeof(type4)); + +//8.5 +if (typeof(type1)===typeof(type2)) +{console.log('type1 and type2 are SameType');} +else {console.log('type1 and type2 are NOT SameType');} + +if (typeof(type1)===typeof(type3)) +{console.log('type1 and type3 are SameType');} +else {console.log('type1 and type3 are NOT SameType');} + +if (typeof(type1)===typeof(type4)) +{console.log('type1 and type4 are SameType');} +else {console.log('type1 and type4 are NOT SameType');} + +if (typeof(type2)===typeof(type3)) +{console.log('type2 and type3 are SameType');} +else {console.log('type2 and type3 are NOT SameType');} + +if (typeof(type2)===typeof(type4)) +{console.log('type2 and type4 are SameType');} +else {console.log('type2 and type4 are NOT SameType');} + +if (typeof(type3)===typeof(type4)) +{console.log('type3 and type4 are SameType');} +else {console.log('type3 and type4 are NOT SameType');} + + + + + +//9 +let X = 7 ; +X = X % 3; +console.log(X = X % 3); +console.log(X %= 3); +console.log(X); + +//10.1 +let multipleTypesArray = ['class', 21 , true]; +console.log(typeof(multipleTypesArray[0])); +console.log(typeof(multipleTypesArray[1])); +console.log(typeof(multipleTypesArray[2])); + +//10.2 +let x1 = 6/0; +let y1 = 10/0; +x1 === y1? console.log('Yes') : console.log('No');