$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · easy · #54

What is the correct fix?

switch (kind) {
  case 'a':
    total += 1;
  case 'b':
    total += 10;
}
  1. Add break; at the end of each case
  2. Add return; at the end of each case
  3. Change switch to a chain of ifs
  4. Move case 'b' above case 'a'
Without break the cases fall through, so 'a' also runs the 'b' branch.
Play Problem Solving ▸