if...else and else if statements Flashcards

1
Q

What keyword specifies an action when all tests above have failed?

A

else

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the keywords that test for a condition when all tests above it have failed?

A

else if

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

In one word, what type of statement is formatted the same way as else and else if?

A

if

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the last line of an else block?

A

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Code an else block that displays an alert saying “Nope”.

A

else {
alert(“Nope”);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Code an else if block that tests whether a has the same value as b. If so, display an alert that says “OK”.

A
else if (a === b) {
  alert("OK");
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Code an else block that assigns the value of one variable to another.

A

else {
num2 = num1;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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.

A

else {
num = 12;
alert(“OK”);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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.

A
else if (a !== b) {
  response = prompt("How many dogs do you own?");
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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.

A
if (a >= b) {
  alert("OK");
}
else {
  alert("Not OK");
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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.

A
if (a < b) {
  alert("Smaller");
}
else if (a > b) {
  alert("Bigger");
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly