Https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements

Tell us what’s happening:
I tried to follow the help video and make the code as identical as possible but no dice.

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;
}
// Change this value to test
switchOfStuff(a);




Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 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

Can you tell us the error that you are receiving within the console? If you take a look at the error that it is giving you now, it should give you more insight into why this problem is happening.

I imagine you are getting an error like a is not defined
It is not. It is stopping your code from executing.
Change function argument or defined the variable, the choice is yours

Im getting the following:

// running tests ReferenceError: a is not defined

switchOfStuff("a")

should have a value of “apple”

switchOfStuff("b")

should have a value of “bird”

switchOfStuff("c")

should have a value of “cat”

switchOfStuff("d")

should have a value of “stuff”

switchOfStuff(4)

should have a value of “stuff” You should use a

default

statement // tests completed // console output ReferenceError: a is not defined

this error is stopping the function from executing, so all tests never run, and you fail them by default

solve this error, as I said above, and you will see the actual results of the tests

Hi,

Instead of assigning a,

switchOfStuff(a);

replace it with a with single quotes.

switchOfStuff(‘a’);

To test if it works,

console.log( switchOfStuff(‘a’));

PS: I have tested with this solution mentioned above. No error shown so far.

Hope this helps :slight_smile: