This repository was archived by the owner on May 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 255
Hani's homework of javascript-week1 #211
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| 'use strict'; | ||
|
|
||
| //Exercise 1: Hello world! | ||
|
|
||
| console.log('hallo,', 'wereld!'); //Nederlands | ||
| console.log('Hallo,', 'Welt!'); //german | ||
| console.log('Ciao,', 'mondo!'); // Italian | ||
| console.log('Hola,', 'mundo!'); // Spanish | ||
| console.log('Olá,', ' Mundo!'); //Portugal | ||
| console.log("Selam,", "Dünya!"); //Turkia | ||
| console.log('Halo,', 'dunia!'); // Indonesian | ||
| console.log('Bonjour,', 'le monde!'); //Bonjour le monde franca | ||
| console.log('Hai,', 'dunia!'); //Malay | ||
| console.log('Kia,', 'ora!'); //Maori |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| 'use strict'; | ||
|
|
||
| //Exercise 10: Compare arrays | ||
|
|
||
|
|
||
| const array1 = ['aaa', '333', false, { color: "blue" }]; | ||
| const array2 = ['up', 'down', 'right', 'left', 'forward', 'behind', 'middle']; | ||
| console.log('the length of array1 is '+ array1.length); | ||
| console.log('the length of array1 is '+ array2.length); | ||
| if (array1.length == array2.length) { | ||
| console.log('They are the same!') | ||
| } else { | ||
| console.log("Two different sizes!"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| 'use strict'; | ||
|
|
||
| //Exercise 2: Error debugging | ||
|
|
||
| console.log("I'm awesome"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| 'use strict'; | ||
|
|
||
| //Exercise 3: Log the number | ||
|
|
||
| let numberX; //step1 | ||
| console.log("x is a variable can be any number ") //step2 | ||
| console.log("I will give x the value 5") //step3 | ||
| numberX = 5; //step4 | ||
| console.log("I think the value must be 5 now (:") //step5 | ||
| console.log(numberX) //step6 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| 'use strict' | ||
|
|
||
| //Exercise 4: Log the string | ||
|
|
||
| //1-Write a console.log statement in which you explain in words what you think the value of the string is. | ||
| let myString = "Hani Badran"; | ||
|
|
||
| //2-Write a console.log statement in which you explain in words what you think the value of the string is. | ||
| console.log("This is my name"); | ||
|
|
||
| //3-Now "console.log" the variable 'myString'. | ||
| console.log(myString); | ||
|
|
||
| //4-Now reassign to the variable 'myString' a new string. | ||
| myString = "Amsterdam" | ||
|
|
||
| //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. | ||
| console.log('and this is my favorite city'); | ||
|
|
||
| //6-Now console.log myString again. | ||
| console.log(myString); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| 'use strict' | ||
|
|
||
| //Exercise 5: Round a number and log it | ||
|
|
||
| //1-Declare a variable 'z' and assign the number 7.25 to it. | ||
| const z = 7.25; | ||
|
|
||
| //2-Write a 'console.log' statement in which you log the value of 'z'. | ||
| console.log(z); | ||
|
|
||
| //3-Declare another variable 'a' that has the value of 'z' but rounded to the nearest integer. | ||
| const a = 7; | ||
|
|
||
| //4-Write a 'console.log' statement in which you log the value of 'a'. | ||
| console.log(a); | ||
|
|
||
| //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. | ||
|
|
||
| const highest = a > z ? a : z; | ||
|
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! Do you know that you can also use Math.max ? |
||
|
|
||
| //6-Write a console.log statement in which you log the value of the highest value. | ||
| console.log(highest); | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| 'use strict' | ||
|
|
||
| //Exercise 6: Log an array of animals | ||
|
|
||
| //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'. | ||
| let colors = []; | ||
|
|
||
| //2-Write a 'console.log' statement that explains in words what you think the value of the array is. | ||
| console.log('this is the basic colors'); | ||
|
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. is this the value of the array? |
||
|
|
||
| //3-Write a 'console.log' statement that logs the array. | ||
| console.log('["red", "green", "blue"]'); | ||
|
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. I think it should log the array |
||
|
|
||
| //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. | ||
| const animals = ['cats', 'dogs', 'horses']; | ||
|
|
||
| //5-Write a 'console.log' statement that logs the second array. | ||
| console.log(animals); | ||
|
|
||
| //6-Add a statement that adds another string ("Piglet") to the array of animals. | ||
| animals.push('Piglet'); | ||
|
|
||
| //7-Write a 'console.log' statement that logs the second array! | ||
| console.log(animals); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| 'use strict'; | ||
|
|
||
| //Exercise 7: Log the length of a string | ||
|
|
||
| //1-Declare a variable called 'mySentence' and initialize it with the following string: "Programming is so interesting!". | ||
| const mySentence = 'Programming is so interesting!'; | ||
|
|
||
| //2-Figure out (using Google) how to get the len-gth of mySentence. | ||
| const length = mySentence.length; | ||
|
|
||
| //3-Write a console.log statement to log the length of mySentence. | ||
| console.log(length); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| 'use strict'; | ||
|
|
||
| //Exercise 8: Type checker | ||
|
|
||
| const str1 = 'aaa'; | ||
| const str2 = 'bbb'; | ||
| const obj1 = ['ccc', 'ddd']; | ||
| const obj2 = ['eee', 'fff']; | ||
| if (typeof str1 == typeof str2) { | ||
| console.log('SAME TYPE'); | ||
| } else { | ||
| console.log('not the SAME...'); | ||
| } | ||
|
|
||
| if (typeof str1 == typeof obj1) { | ||
| console.log('SAME TYPE'); | ||
| } else { | ||
| console.log('not the SAME...'); | ||
| } | ||
|
|
||
| if (typeof str1 == typeof obj2) { | ||
| console.log('SAME TYPE'); | ||
| } else { | ||
| console.log('not the SAME...'); | ||
| } | ||
|
|
||
| if (typeof str2 == typeof obj1) { | ||
| console.log('SAME TYPE'); | ||
| } else { | ||
| console.log('not the SAME...'); | ||
| } | ||
|
|
||
| if (typeof str2 == typeof obj2) { | ||
| console.log('SAME TYPE'); | ||
| } else { | ||
| console.log('not the SAME...'); | ||
| } | ||
| if (typeof str2 == typeof str1) { | ||
| console.log('SAME TYPE'); | ||
| } else { | ||
| console.log('not the SAME...'); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| 'use strict'; | ||
|
|
||
| //Exercise 9: Log the remainder | ||
|
|
||
| //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. | ||
|
|
||
| //if x equals 7, and the only other statement is x = x % 3, the value of x after the calculation will be 1. | ||
| let x = 7; | ||
| x %= 3 ; | ||
| console.log(x); | ||
|
|
||
| //if y equals 21, and the only other statement is y = y % 4, the value of x after the calculation will be 1. | ||
| let y = 21; | ||
| y %= 4; | ||
| console.log(y); | ||
|
|
||
| //if z equals 13, and the only other statement is z = z % 2, the value of x after the calculation will be 1. | ||
| let z = 13; | ||
| z %= 2; | ||
| console.log(z); | ||
|
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. Nice! |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| //Exercise 1: Remove the comma | ||
|
|
||
| 'use strict'; | ||
|
|
||
| let myString = 'hello,this,is,a,difficult,to,read,sentence'; | ||
| console.log(myString.length); | ||
| myString = myString.replace(/,/g," "); | ||
| console.log(myString) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| //Exercise 2: The even/odd reporter | ||
|
|
||
| 'use strict'; | ||
|
|
||
| for (let i = 0; i <= 20; i++) | ||
| { | ||
| if(i % 2 === 1) | ||
| { | ||
| console.log(`The number ${i} is odd!`) | ||
| }; | ||
| if(i % 2 === 0) | ||
| { | ||
| console.log(`The number ${i} is even!`) | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| //Exercise 3: The recipe card | ||
|
|
||
| 'use strict'; | ||
|
|
||
| const recipe = { | ||
| MealName: 'Papa oats', | ||
| Serves: 3, | ||
| Ingredients:[ '120 Gr Oats', '120 Gr Water', '30 Gr olive oil', '30 Gr honey', '1 tsp salt'], | ||
| }; | ||
|
|
||
| let entries = Object.entries(recipe); | ||
|
|
||
| for(entries of entries){ | ||
| console.log(entries) | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Ah I understand, but what is the value at this moment?