Java script switch function

Tell us what’s happening:
I can’t figure out what’s wrong in this code I wrote for switch, need help folks

  **Your code so far**

function switchOfStuff(val) {
var answer = "";
// Only change code below this line
switch (answer){
  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;
}

switchOfStuff(1);
  **Your browser information:**

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

Challenge: Adding a Default Option in Switch Statements

Link to the challenge:

Check what you are passing as an argument to switch.

Write a switch statement to set answer for the following conditions:
a - apple
b - bird
c - cat
default - stuff
this is what i am trying to code

Whenever someone calls the switchOfStuff() function, whatever argument they provide will be stored in val, which the switch statement would also use to check.

Change the argument in switch from answer to val.

yes it worked, thank you.

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