A switch with grouped cases and a default
Pick another day in the menu. Stacked case labels share one block of code.
switch compares one value against a list of case values with === and jumps to the first match; execution then falls through into the next cases until a break, and default handles no match. For pure value-to-value mapping, an object or Map is often better.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write a switch that turns a number 1 to 3 into gold, silver, bronze, and anything else into no medal. Print the result for 2 and 7.
Rewrite the medal mapping as a lookup with a fallback, so there is no switch at all.
Explain it without notes
How does switch decide which case matches?
What is fall-through, and when is it useful?
When would you use an object or Map instead of a switch?
Why can declaring let inside a case cause an error, and how do you fix it?
Preview
Console
Nothing logged yet.Expected console output
Rest and play | Work, then movie night | Work and study | Unknown day