What is the correct fix?
switch (kind) {
case 'a':
total += 1;
case 'b':
total += 10;
}
- Add
break;at the end of each case - Add
return;at the end of each case - Change
switchto a chain ofifs - Move
case 'b'abovecase 'a'
Without break the cases fall through, so 'a' also runs the 'b' branch.
Play Problem Solving ▸