Basic JavaScript - Adding a Default Option in Switch Statements

Tell us what’s happening:

Am i supposed to set this up as them each having their own function? I set it up correctly I believe. I just cant see where the issue is. Any pointers would be amazing!

Your code so far

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

switchOfStuff(1);

Your browser information:

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

Challenge Information:

Basic JavaScript - Adding a Default Option in Switch Statements

Why do you have the function name here? Are you not supposed to have a switch statement?

the function at the top? or the statement below the line?

The statement below the line.

it is part of the example for the task, I have removed it to try without it and it didn’t change my current outcome. I have been trying different variants to see if that helps at all

Within your code, there should be a switch statement, just as the example suggests here.

switch (num) {
  case value1:
    statement1;
    break;
  case value2:
    statement2;
    break;
...
  default:
    defaultStatement;
    break;
}

replace that function name with a switch statement.

2 Likes

Good point. Thats a great deal.

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