Basic JavaScript - Adding a Default Option in Switch Statements

Tell us what’s happening:
Describe your issue in detail here.
I have a question why is after case it has to be the string “a”, “b” or “c” instead of just a,b,c

Your code so far

function switchOfStuff(val) {
  let 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;
}

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: Basic JavaScript - Adding a Default Option in Switch Statements

Link to the challenge:

Hello!

That’s in the nature of the switch statement:
It expects a type string or a type integer (number), or you will get an undefined.

Remember the three data types we are working most with in programming:
String, integer and boolean.

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