Switch a Venue Sign
Before choosing an effect for a stage prop, use switch to assign a message for a venue sign. Each case handles one exact value. break prevents the message from being overwritten by a later case.
javascript
const entrance = "west";
let direction;
switch (entrance) {
case "west":
direction = "Use the garden gate";
break;
case "east":
direction = "Use the river gate";
break;
default:
direction = "Ask at reception";
}
console.log(direction);
The first block matches west and stops at its break. The next block uses an unknown entrance. Predict its output before running it:
javascript
const entrance = "north";
let direction;
switch (entrance) {
case "west":
direction = "Use the garden gate";
break;
case "east":
direction = "Use the river gate";
break;
default:
direction = "Ask at reception";
}
console.log(direction);
In the next exercise, use the same choice pattern in a function that selects a stage-prop effect; a return can replace the assignment and break.