Selecting from many options with Switch Statements

Selecting from many options with Switch Statements


My code successfully passed the test, but I also get an error code in the text editor. My code (in between the comments) is below. I have four yellow triangles that state “Unreachable ‘break’ after ‘return’.” Is this normal, or have I done something wrong?

function caseInSwitch(val) {
var answer = “”;
// Only change code below this line
switch (val) {
case 1:
case 2:
case 3:
case 4:


// Only change code above this line
return answer;

// Change this value to test


Hey, normally break; is used to “break out” of the switch statement. In your case, you stop executing the switch statement by using the return key word. So the break; is not necessary here.


Thanks @BenGitter
I also did things a little differently on the next challenge and realised instead of using return I could (should?) have used answer = “alpha”;, and then I could have used break as the challenge requires :slight_smile:


It’s worthwhile noting that using a return in a case statement, is the only good reason to omit the break;
In any other case, where you’re not exiting the switch statement with a return, the break should always be there.