switch Statement, online

Six activities your students do on their own devices. See who's finished, and their scores.

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

Discover other journeys with this module

What students will learn in this module

Every question in Module 18

Quick questions

  1. Does switch compare a value against multiple case labels?AYesBNo
  2. Does each case label end with a colon?AYesBNo
  3. Is 'Switch' with a capital S valid JavaScript syntax?ANoBYes
  4. Does break stop the code from running into the next case?ANoBYes
  5. 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 does
case 3:Match it to what it does
Stops the code from falling into the next caseMatch it to what it does
Runs when no case value matchesMatch it to what it does
case 1Match it to what it does
Break;Match it to what it does

Fill in the blanks

  1. ______ (day) {

    Hint: Type the keyword that starts a switch statement.

  2. case 1:
    console.log("Monday");
    _____;

    Hint: Type the keyword that stops the code falling into the next case.

  3. case _:
    console.log("Two");
    break;

    Hint: Type the value this case matches.

  4. _______:
    console.log("Fallback");

    Hint: Type the keyword used as the fallback case.

  5. 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;