Basic JavaScript - Selecting from Many Options with Switch Statements

Tell us what’s happening:
seems like there is something wrong with my val

it diagnoses a problem in the letter c for the case 1]
l

Your code so far

function caseInSwitch(val) {
  let answer = "";
  // Only change code below this line
  case 1:
  answer += "alpha";
  break;
  case 2:
  answer += "beta";
  break;
  case 3:
  answer += "gamma";
  break;
  case 4:
  answer += "delta";


  // Only change code above this line
  return answer;
}

caseInSwitch(1);

Your browser information:

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

Challenge: Basic JavaScript - Selecting from Many Options with Switch Statements

Link to the challenge:

You’re missing the first part of the switch/case format

As the previous comment mentioned, to begin a switch statement you will need to include the keyword switch. The implementation looks like:

switch (val) { 
  case 1: 
    answer += "alpha";
    break;
  // other cases...
}

It’s best practice to include a default: statement at the end of your switch statement. This ensures that if none of the cases match, you don’t unintentionally return an undefined value. The implementation looks exactly like a case statement:

case 4:
  answer += "delta";
  break;
default: 
  return "no matching case";

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