Created
July 6, 2020 10:35
-
-
Save ivanteoh/187cd2c5176115af6ea331010faed9ed to your computer and use it in GitHub Desktop.
Javascript: 101 Week 1 Track 2
This file contains 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
(4 >= 6 || "grass" != "green") && !(12 * 2 == 144 && true) |
This file contains 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
var total = 2; | |
var count = 1; | |
while (count < 10) { | |
total = total * 2; | |
count = count + 1; | |
} | |
alert(total); |
This file contains 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
var triangle = ""; | |
var line = 0; | |
while (line < 10) { | |
var count = 0; | |
line = line + 1; | |
hash = ""; | |
while (count < line) { | |
hash = hash + "#"; | |
count = count + 1; | |
} | |
triangle = triangle + hash + '\n'; | |
} | |
alert(triangle); |
This file contains 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
for (var total = 2, count = 1; count < 10; count++) { | |
total = total * 2; | |
} | |
alert(total); |
This file contains 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
for (var line = 0, triangle = ""; line < 10; line++) { | |
for (var count = 0, hash = ""; count <= line; count++) { | |
hash = hash + "#"; | |
} | |
triangle = triangle + hash + '\n'; | |
} | |
alert(triangle); |
This file contains 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
var theNumber = prompt('What the value of 2 + 2 is?', ''); | |
if (theNumber == '4') | |
alert('Correct! Well done.'); | |
else if (theNumber == '3' || theNumber == '5') | |
alert('Almost!'); | |
else | |
alert('Ops! Please try again!'); |
This file contains 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
while (true) { | |
var theNumber = prompt('What the value of 2 + 2 is?', ''); | |
if (theNumber == '4') { | |
alert('Correct! Well done.'); | |
break; | |
} | |
else if (theNumber == '3' || theNumber == '5') | |
alert('Almost!'); | |
else | |
alert('Ops! Please try again!'); | |
} |
This file contains 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
function absolute(number) { | |
if (number < 0) | |
return -number; | |
return number; | |
} |
This file contains 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
function greaterThan(number1) { | |
function test(number2) { | |
return number2 > number1; | |
} | |
return test; | |
} | |
var greaterThanTwenty = greaterThan(20); | |
alert(greaterThanTwenty(52)); | |
alert(greaterThanTwenty(10)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment