I can't run my caseInSwitch function test

Hey! I’m frustratedly stuck in this caseInSwitch function test. It keeps on underlining “case” with declaration or statement expected error
Plus I can’t even run the test to know what’s wrong, when i try to run the test nothing happens.
Here’s my code:

function caseInSwitch(val) {
var answer = "";
// Only change code below this line
case 1: 
 answer = "alpha";
case 2:
  answer = "beta";
case 3:
  answer = "gamma";
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/91.0.4472.124 Safari/537.36

Challenge: Selecting from Many Options with Switch Statements

Link to the challenge:

You can’t just throw some case keywords into the code, they need to be wrapped by a switch:

switch(val){
  case 1: answer = "alpha"
}

I guess the fact that the outer function already has “switch” in its name might have been confusing here.

so please what do you suggest i should do?

Take a look at the example code in the challenge description, to understand the syntax of a switch. The switch takes a value (lowercaseLetter in this case), and has a number of cases. If lowercaseLetter is "a", the code for the first case will run.

switch(lowercaseLetter) {
  case "a":
    console.log("A");
    break;
  case "b":
    console.log("B");
    break;
}

Your code has no switch, it only has some case keywords, but those make no sense when there’s no switch surrounding them.

1 Like

Ooh my bad
Thanks a lot, I don’t know wtf I was thinking.
Thank you.

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