-
Notifications
You must be signed in to change notification settings - Fork 254
Riam Alali-week2hw #110
Riam Alali-week2hw #110
Changes from all commits
880346a
ae54b78
a92d297
803f81f
75510a1
8c22a3d
a221ead
769f2d8
ee5ec25
f147d04
62e1263
b029430
e76e2cb
7c24d80
3297e1c
8affdb4
a5d7480
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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'); | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure that the value of |
||
| console.log (x); | ||
| x = 8 ; | ||
| console.log ("the value of my variable x will be:EvenNumber"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure that the value of x is |
||
| console.log (x) | ||
|
|
||
| //4 | ||
| let y = "HackYourFuture" | ||
| console.log ("the value of the string is "+"HackYourFuture") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't forget to add |
||
| 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){ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good! You can also use math.max, but this solution is fine:) |
||
| highest=z; | ||
| } | ||
| else{ | ||
| highest=a; | ||
| } | ||
| console.log(highest); | ||
|
|
||
|
|
||
| //6 | ||
| let FavoriteAnimals = [ ]; //6.1 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should not use capital letters for the variable names. So
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you fix this one? |
||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah nice, you can also use Which might be an easier solution |
||
| 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');} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tip: The code is easier to read if you add more spaces in between the if statement, like this: |
||
| 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 ; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use lowercase
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this one, then the homework is approved! |
||
| 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'); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that you did all your homework in one file, but the assignment was to make one file for each part of the homework:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your review, I'v made changes as advised, could you please re-check?