Loops and Conditions
Conditionals
if (booleanExpression) {
// do thing 1
} else if (otherBooleanExpression) {
// do thing 2
} else {
// do something else
}let num = prompt("Enter a number"); // recall that this allows the user to input a value
if (num === null) { // prompt() returns null if the user gives no input
alert("You did not enter a number");
} else if (num % 2 === 0) {
alert("The number you entered was even");
} else {
alert("The number you entered was odd");
}
Ternary operation
Loops


ReferenceError: i is not defined in grey text, because the program has not yet run but the console knows what the result is going to be. This tells me as the programmer to look for the problem and fix it before running the code.
Next steps
Last updated