Adding a Default Option in Switch Statements not working

Looked through the code many times and through the forum and can’t locate where the problem lies…anyone provide a tip please?
cheers
col

Your code so far


function switchOfStuff(val) {
var answer = "";
// Only change code below this line
switch (val){ 
case "a":
  answer = "apple";
  break;
case "b":
  answer = "bird";
  break;
case "c":
  answer = "cat";
  break;
default:
  answer = "stuff";
// Only change code above this line
return answer;
}

// Change this value to test
switchOfStuff(d);
}

Your browser information:

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

Challenge: Adding a Default Option in Switch Statements

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements

Hi, the main problem is that your return statement is inside switch statement. It is unreachable after break.
By the way, you should add break for default statement, too.
Your test case d is a undefined variable.
For your reference.

The return statement, as it says, can’t be changed…is this wrong?

If I add a break statement to for default, that comes back as incorrect when I run the code…

Thanks for the pointer regarding the test case…
cheers
col

Because I can’t run the code…I get a SyntaxError: unknown: Unexpected token (24:0) error…

I have finally figured it out…moved the second last } and it worked

cheers
col