1
2
3
4
5
6
7
8
9
10
To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to CodePen.
0,1,2,3,4,5,6,7,8,9
0
0
0
0
Code the first line of a switch statement. Make up the variable name. | switch (num) { | switch\([a-z_$][a-zA-Z0-9_$]*\){ | |
Code the second line of a switch statement that's testing for a string. Make up the string. Don't bother to indent. | case "abc": | case•.*•: | |
Assuming there are no more statements to execute, fill in the blank. | switch (petSnakeGender) { case "female": name = "Lydia"; __________ |
break; | break; |
Type the statement that's missing from this code. | switch (num) { case 12: alert("It's a dozen!"); default: alert("It's not a dozen."); |
break; | break; |
Type the line that says what happens when no tests have been successful. Don't bother to indent. | default: | default: | |
Code the first 4 lines of a switch statement that tests an integer variable. If the first condition is true, display an alert. Make up everything. | switch (num) { case 12: alert("It's a dozen!"); break; |
switch\([a-z_$][a-zA-Z0-9_$]*\){[\r\n]case(0|-?[1-9][\d]*):[\r\n]alert\(•.*•\);[\r\n]break; | |
Code a switch statement that duplicates the functionality of this code. | if (num === 0) { alert("none"); } else { alert("some"); } |
switch (num) { case 0: alert("none"); break; default: alert("some"); } |
switch\(num\){[\r\n]case0:[\r\n]alert\(•none•\);[\r\n]break;[\r\n]default:[\r\n]alert\(•some•\);[\r\n]} |
Code a switch statement that tests for a string. It contains one case and a default. If the case tests true, display an alert. If not, display another alert. Make up everything. | switch (title) { case "president": alert("Very impressive!"); break; default: alert("Maybe in your future"); } |
switch\([a-z_$][a-zA-Z0-9_$]*\){[\r\n]case•.*•:[\r\n]alert\(•.*•\);[\r\n]break;[\r\n]default:[\r\n]alert\(•.*•\);[\r\n]} | |
|
|||
|