FreeCodeCamp, issue with lesson: "Selecting from many options with Switch Statements"

My code which you can see on the uploaded image is not working although it is obviously correct and works for “case 4”.

Is there a problem with the FreeCodeCamp website, or is it somewhere in my code, which I seriously doubt?

There is a misplaced bracket at line 25.

It corresponds to the curly bracket at line 5, therefore it is right there where it belongs to. Thank you for your time.

Could be the missing break after case 4’s answer. Also I believe the return should be outside the switch statement but still inside the function.

1 Like

It was not the break but insted the return smply should have been after the curly brace. If this is meant by misplaced, then @Quckz was also right.

Here is the solution:

1 Like

Well done! Yeah I was looking at my solution to that one and noticed the missing break/return placement in comparison. Glad it worked for you :+1:
By the way I don’t think you need the extra break after the default. (I’m just mentioning it in case you want to really master the syntax). I don’t think it being there would necessarily do any harm but it’s kinda superfluous since I believe the default itself acts as a end.

1 Like

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

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