This works but... Basic JavaScript - Selecting from Many Options with Switch Statements

Tell us what’s happening:
Describe your issue in detail here.
So my code worked as I was checking it via console.log but when submitting it, it wouldn’t go through. I formatted it like the example–as this is the first time I’m encountering switch statements, I thought that using “console.log” was the proper way to write this particular kind of code. I would suggest intro’ing the idea of “return” or indicating that we’re to use the variable “answer” here. I know this has been introduced earlier but again since this is the first time I’m learning about switch statements seeing how it should be would be more helpful. Just my two cents :slightly_smiling_face:

Your code so far

function caseInSwitch(val) {
  let answer = "";
  // Only change code below this line
  switch (val) {
    case 1:
    console.log("alpha");
    break;
    case 2:
    console.log("beta")
    break;
    case 3:
    console.log("gamma");
    break;
    case 4:
    console.log("delta");
    break;
  }
  // Only change code above this line
  return answer;
}

caseInSwitch(4);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36

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

Link to the challenge:

The example provided of how to use a switch is accurate. Any code can go into the case (which we don’t explicitly say though).

The intent behind proving an example you cannot copy-paste is that we want to ease you away from copy-paste and towards thinking about what syntax you know will help you meet your goals.

1 Like

Thanks for the reply! I understand switch statements better now after having gone through the next couple lessons.

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