Selecting from many options with Switch Statements not correct but passes the test

Tell us what’s happening:
I don’t really have a problem with the solution but I brought up a solution that is wrong and it is accepted as is.

Fact is that the break in this solution is unreachable because of the return value (instead of console.log).
I don’t know if I’m correct but I think this should not be marked as correct.

Your code so far

function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch(val){
  case 1:
    answer = "alpha";
    return answer;
    break;
  case 2:
    answer = "beta";
    return answer;
    break;
  case 3:
    answer = "gamma";
    return answer;
    break;
  case 4:
    answer = "delta";
    return answer;
    break;
  default:
    answer = "only 1 to 4 please";
  }
  
  
  // Only change code above this line  
  return answer;  
}

// Change this value to test
caseInSwitch(1);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36.

Link to the challenge:
https://www.freecodecamp.org/challenges/selecting-from-many-options-with-switch-statements

1 Like

I just find it weird that the code is accepted although it’s a bad coding way, that’s just my thought.

You mentioned it yourself,
writing useless code is not a good coding habit.
Especially the fact that the editor itself is showing that there’s something wrong with the code, is enough reason not to give permission to the next question until the problem is resolved.
I know that the basics are met but it is still bad code.

But of course, that is only my opinion.

Just finished this one and was wondering what the warning was about. Thanks @lawfets for asking, and thanks @camperextraordinaire for your answer!

Your solution helped me pass off this test when nothing else was working for me.
Thank you.