switch Statement

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

This switch Statement worksheet is part of the JavaScript Coding without HTML and CSS journey. Print it as a booklet?

switch Statement

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Does switch compare a value against multiple case labels?
A Yes
B No
2. Does each case label end with a colon?
A Yes
B No
3. Is 'Switch' with a capital S valid JavaScript syntax?
A No
B Yes
4. Does break stop the code from running into the next case?
A No
B Yes
5. Does switch put the value to compare inside parentheses?
A No
B Yes

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1switch (day) { AWrong - case labels need a colon after the value
2case 3: BMatches when the switch value equals 3
3Stops the code from falling into the next case CCompares day against each case label
4Runs when no case value matches DWrong - 'break' must be lowercase
5case 1 Edefault:
6Break; Fbreak;

Definitions

switch

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
______ (day) {
2.
case 1: console.log("Monday"); _____;
3.
case _: console.log("Two"); break;
4.
_______: console.log("Fallback");
5.
case 5: console.log("Five"); _____;

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A swich (day) {
B case 1:
C break;
Question 2
A switch day) {
B case 2:
C break;
Question 3
A switch (day) {
B case 1
C break;
Question 4
A switch (num) {
B case 5;
C break;
Question 5
A switch (x) {
B case 1:
C Break;

Answer Key

switch Statement
Section A: Quick Questions
Q1
A — Yes
Q2
A — Yes
Q3
A — No
Q4
B — Yes
Q5
B — Yes
Section B: Match the Pairs
Q1
switch (day) { → Compares day against each case label
Q2
case 3: → Matches when the switch value equals 3
Q3
Stops the code from falling into the next case → break;
Q4
Runs when no case value matches → default:
Q5
case 1 → Wrong - case labels need a colon after the value
Q6
Break; → Wrong - 'break' must be lowercase
Section C: Definitions
Q1
switch — Compares a value against multiple case labels and runs the code block for the matching case.
Section D: Fill in the Blanks
Q1
switch (day) {
Q2
case 1: console.log("Monday"); break;
Q3
case 2: console.log("Two"); break;
Q4
default: console.log("Fallback");
Q5
case 5: console.log("Five"); break;
Section E: Spot the Error
Q1
A — 'switch' is misspelled as 'swich'.
Q2
A — Missing the opening parenthesis before day.
Q3
B — Case labels need a colon after the value: case 1:.
Q4
B — Case labels use a colon :, not a semicolon ;.
Q5
C — 'break' must be lowercase - a capital B causes an error.