if...else and else if statements Flashcards
What keyword specifies an action when all tests above have failed?
else
What are the keywords that test for a condition when all tests above it have failed?
else if
In one word, what type of statement is formatted the same way as else and else if?
if
What is the last line of an else block?
}
Code an else block that displays an alert saying “Nope”.
else {
alert(“Nope”);
}
Code an else if block that tests whether a has the same value as b. If so, display an alert that says “OK”.
else if (a === b) { alert("OK"); }
Code an else block that assigns the value of one variable to another.
else {
num2 = num1;
}
Code an else block that assigns a number to a variable and displays an alert specifying a string as the message. The variable has been declared beforehand.
else {
num = 12;
alert(“OK”);
}
Code a block, that, if tests above it fail, checks whether one variable doesn’t equal another and, if so, displays a prompt that assigns the user’s response to a variable that has been declared beforehand.
else if (a !== b) { response = prompt("How many dogs do you own?"); }
Code an if statement that tests whether the value represented by a variable is greater than or equal to the value represented by another variable. If so, display an alert. If not, display a different alert.
if (a >= b) { alert("OK"); } else { alert("Not OK"); }
Code an if statement that tests whether the value represented by a variable is less than the value represented by another variable. If so, display an alert. If not, test whether the value represented by the first variable is greater than the value represented by the second variable. If so, display a different alert.
if (a < b) { alert("Smaller"); } else if (a > b) { alert("Bigger"); }