Adding a Default Option in Switch Statements NOTHING IS WORKING!

Tell us what’s happening:

OK I’m really really frustrated right now. I’ve looked at a half dozen forum threads trying to get this to work and nothing is working. It looks exactly like an answer I found on one of the threads but it only returns “a is not defined”. Help please.

Your code so far

function switchOfStuff(val) {
  var answer = "";
  // Only change code below this line
  switch(val) {

    case 'a':
    answer = "apple";

    case 'b':
    answer = "bird";

    case 'c':
    answer = "cat";

    answer = "stuff";

  // Only change code above this line  
  return answer;  

// Change this value to test

Your browser information:

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

Link to the challenge:

1 Like

hmm, it passed for me when i copied your code. try copying your code, then refresh the page and paste it and try to submit again.

1 Like

Thank you for replying so quickly. I tried refreshing the page and resetting the code and pasting it but nothing works.

Can you post a screenshot which shows the entire page after you click Run the Tests?

The problem is the above line. Why did you put it into your solution? The variable a is not defined anywhere in your code, which is why you are seeing the error “a is not defined”. Get rid of that line and you are good to go.


OK thank you and that worked but I really want to understand this. Isn’t that line to test the function? Isn’t this function basically to return the answer of “apple” when someone were to input “a” for example? If we can’t put a val in the switchOfStuff( ) then what exactly is this function doing? Not trying to be rude or anything I’m just not understanding why that made the program not work.

1 Like

what you wanted to test was switchOfStuff("a"); notice the quotes around the a.

you should absolutely test your functions, but if you pass undeclared variables, everything goes to :poop:

hope that helps!

1 Like

Oh I gotcha. Ok I understand now thank you both for your help.