Reference error confusing

Tell us what’s happening: what am I doing wrong?

  **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";
break;
}


// Only change code above this line
return answer;
}

console.log(switchOfStuff(b));
  **Your browser information:**

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

Challenge: Adding a Default Option in Switch Statements

Link to the challenge:

Hi! Could you describe the error you’re seeing? (I am pretty sure I know what’s happening here, but it’s always good to describe the issue in as much detail as possible.)

The switch statement itself is good. I’m guessing you are using console.log to test? That’s fine, but you can’t use a variable that hasn’t been declared. My guess is you meant to pass in “b” rather than a variable named b.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.