Repository navigation
Abdullah Al Ahmad #114
Abdullah Al Ahmad #114
Changes from 1 commit
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 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
| <title>Document</title> | ||
| </head> | ||
| <body> | ||
| <script src="js1-w2.js"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| // Greetings | ||
|
|
||
| console.log ('Hello World!'); //English | ||
|
|
||
| console.log ('Halo, Dunia!'); // Indonesian | ||
|
|
||
| console.log ('Ciao Mondo!'); // Italian | ||
|
|
||
| console.log ('Hola Mundo!'); // Spanish | ||
|
|
||
|
|
||
| // Debug single quote issue | ||
|
|
||
| console.log('I\'m awesome'); | ||
|
|
||
| // Variables & Values | ||
|
|
||
| var x; | ||
|
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. Don't use |
||
|
|
||
| console.log("the value of my variable x will be: a number"); | ||
|
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 don't think the value of |
||
|
|
||
| console.log(x); | ||
|
|
||
| x = 12; | ||
|
|
||
| console.log("the value of my variable x will be: a number"); | ||
|
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 don't think the value of |
||
|
|
||
| console.log(x); | ||
|
|
||
| var y = 'Tom'; | ||
|
|
||
| console.log("the value of my atring y will be: a name"); | ||
|
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. Here the same:) as above |
||
|
|
||
| console.log(y); | ||
|
|
||
| var y = y + '&Jerry'; | ||
|
|
||
| console.log("the value of my string y will be: a cartoon name"); | ||
|
|
||
| console.log(y); | ||
|
|
||
| var z = 7.25; | ||
|
|
||
| console.log(z); | ||
|
|
||
| // Round z to the closest integer | ||
|
|
||
| var round = Math.round; | ||
|
|
||
| var a = round(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, you can also do this in one line, like this:
|
||
|
|
||
| console.log(a); | ||
|
|
||
| // Print higher value z or a | ||
|
|
||
| if (a<z) { | ||
| var i = z; | ||
| console.log(i); | ||
|
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 can also do this directly:
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. Or with Math.max |
||
|
|
||
| } else { | ||
| var i = a; | ||
| console.log(i); | ||
|
|
||
| } | ||
|
|
||
| // Animals Names | ||
|
|
||
| var myFavoriteAnimals; | ||
|
|
||
| console.log('The value of heros is: animales\'s names'); | ||
|
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 don't think this is correct, |
||
|
|
||
| console.log(myFavoriteAnimals); | ||
|
|
||
| myFavoriteAnimals = ['monkey', 'horse', 'turtle']; | ||
|
|
||
| console.log(myFavoriteAnimals); | ||
|
|
||
| myFavoriteAnimals = myFavoriteAnimals + [', baby pig']; | ||
|
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. A cleaner (and better) solution is:
I think this works better:) |
||
|
|
||
| console.log(myFavoriteAnimals); | ||
|
|
||
| // String Length | ||
|
|
||
| let myString = "this is a test"; | ||
|
|
||
| console.log(myString); | ||
|
|
||
| console.log(myString.length); | ||
|
|
||
| // Types of Data | ||
|
|
||
| var success = 'Congats! the data type of your variables is identical!'; | ||
|
|
||
| console.log(success + ' * this is a string'); | ||
|
|
||
| console.log(typeof success); | ||
|
|
||
|
|
||
| var failure = 'Oops! the data type of your variables is different!'; | ||
|
|
||
| console.log(failure + ' * this is a string'); | ||
|
|
||
| console.log(typeof failure); | ||
|
|
||
|
|
||
| var number = 1; | ||
|
|
||
| console.log(number + ' * this is a number'); | ||
|
|
||
| console.log(typeof number); | ||
|
|
||
|
|
||
| var boolean = true; | ||
|
|
||
| console.log(boolean + ' * this is a boolean'); | ||
|
|
||
| console.log(typeof boolean); | ||
|
|
||
|
|
||
| var array = [0, 1, 2, 3, 4]; | ||
|
|
||
| console.log(array + ' * this is an object'); | ||
|
|
||
| console.log(typeof array); | ||
|
|
||
| // Testing type of data | ||
|
|
||
| if (typeof success === typeof failure) { | ||
|
|
||
| console.log(success); | ||
|
|
||
| } else { | ||
| console.log(failure); | ||
| } | ||
|
|
||
|
|
||
| if (typeof success === typeof number) { | ||
| console.log(success); | ||
|
|
||
| } else { | ||
| console.log(failure); | ||
| } | ||
|
|
||
|
|
||
| if (typeof boolean === typeof array) { | ||
| console.log(success); | ||
|
|
||
| } else { | ||
| console.log(failure); | ||
| } | ||
|
|
||
| // Explaining % | ||
|
|
||
| console.log(x); | ||
|
|
||
| console.log ('x % 5 will be 2 which is the leftover number that cannot be divided on 5'); | ||
|
|
||
| console.log(x % 5); | ||
|
|
||
| // Array with multiple data types | ||
|
|
||
| console.log('following array contains 2 numbers, 2 strings and a boolean'); | ||
|
|
||
| var multipleTypesArray = [0, 'hero', 2, 'too', false]; | ||
|
|
||
| console.log(multipleTypesArray); | ||
|
|
||
| // Comparing infinities | ||
|
|
||
| if (10/0 === 6/0) { | ||
| console.log('Yes! they\'re equal!'); | ||
|
|
||
| } else { | ||
| console.log('There\'s no equality in this!'); | ||
| } | ||
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.
Can you split your homework up in different files? As requested in the assignment: