Skip to content

Instantly share code, notes, and snippets.

@ivanteoh
Created July 6, 2020 10:35
Show Gist options
  • Save ivanteoh/187cd2c5176115af6ea331010faed9ed to your computer and use it in GitHub Desktop.
Save ivanteoh/187cd2c5176115af6ea331010faed9ed to your computer and use it in GitHub Desktop.
Javascript: 101 Week 1 Track 2
(4 >= 6 || "grass" != "green") && !(12 * 2 == 144 && true)
var total = 2;
var count = 1;
while (count < 10) {
total = total * 2;
count = count + 1;
}
alert(total);
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);
for (var total = 2, count = 1; count < 10; count++) {
total = total * 2;
}
alert(total);
for (var line = 0, triangle = ""; line < 10; line++) {
for (var count = 0, hash = ""; count <= line; count++) {
hash = hash + "#";
}
triangle = triangle + hash + '\n';
}
alert(triangle);
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!');
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!');
}
function absolute(number) {
if (number < 0)
return -number;
return number;
}
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