The neighbourhood head delivers a letter through the switch house: which room plate matches, and where does he walk once he is in that room? Put a break in or…
Accidental fallthrough is a classic bug: one case’s logic leaks into the case below. Add the === matching that often surprises (values from an input are always text). Knowing when fallthrough is meant and when an object lookup is better keeps your control flow clean.
switch keeps going until it meets a break
break. Add break/return, or write a // falls through comment when it is on purpose.switch(2) never hits case "2" switch uses ===: "2" ≠ 2. Make the types the same first (for instance Number(x)), above all for values from an input, which are always text.{ 1: 'Bu Yanti', 2: 'Rizal' }[kamar]) is shorter and has no break to forget.2 with break The case 1 plate does not match, case 2 does: Rizal gets the letter, then break takes the neighbourhood head out.break out of case 2 The neighbourhood head walks on into Dina’s room without reading its plate: two letters.'2' (text) '2' === 2 is false: switch uses ===, so the letter goes into the post box.switch (Number(kamar)) Turn the text '2' into a number first, and then the case 2 plate matches.