switch Statement, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
switch Statement in one minute
What students need to know
break exits the switch once a matching case has run. default is the fallback case in a switch statement.
switch checks the value against each case in turn. A case label is written as case value:.
Mistakes students make
- 'switch' is misspelled as 'swich'.
- Missing the opening parenthesis before day.
- Case labels need a colon after the value: case 1:.
- Case labels use a colon :, not a semicolon ;.
PREVIOUS · MODULE 17Ternary Operator
YOU ARE HERE · MODULE 18switch Statement
NEXT · MODULE 19While Loops
What students will learn in this module
Every question in Module 18
Quick questions
- Does switch compare a value against multiple case labels?AYesBNo
- Does each case label end with a colon?AYesBNo
- Is 'Switch' with a capital S valid JavaScript syntax?ANoBYes
- Does break stop the code from running into the next case?ANoBYes
- Does switch put the value to compare inside parentheses?ANoBYes
Key terms
Students type the meaning of:
switch
Match the pairs
switch (day) {Match it to what it doescase 3:Match it to what it doesStops the code from falling into the next caseMatch it to what it doesRuns when no case value matchesMatch it to what it doescase 1Match it to what it doesBreak;Match it to what it doesFill in the blanks
______ (day) {Hint: Type the keyword that starts a switch statement.
case 1: console.log("Monday"); _____;Hint: Type the keyword that stops the code falling into the next case.
case _: console.log("Two"); break;Hint: Type the value this case matches.
_______: console.log("Fallback");Hint: Type the keyword used as the fallback case.
case 5: console.log("Five"); _____;Hint: Type the keyword that stops the code falling into the next case.
Spot the error
Question 1
Aswich (day) {Bcase 1:Cbreak;
Question 2
Aswitch day) {Bcase 2:Cbreak;
Question 3
Aswitch (day) {Bcase 1Cbreak;
Question 4
Aswitch (num) {Bcase 5;Cbreak;
Question 5
Aswitch (x) {Bcase 1:CBreak;
