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";
    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(a);

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:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements

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.

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.