Selecting from Many Options with Switch Statements. HEELLPP PLEEEASE

Tell us what’s happening:

Your code so far


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

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

// Change this value to test
caseInSwitch(val);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36 OPR/63.0.3368.107.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements/

1 Like

switch uses strict comparison (like ===) for checking the cases against the test value. Here the test value is expected to be a number, but the cases are all strings.

You’re also missing a } after the last break

1 Like

Thank you. “cool cat”

1 Like

Also, just a heads up to save you some typing, the return statement already breaks the flow of logic, so adding a break; statement below it is redundant, and the breaks will never be reached anyway.

1 Like

Got it. Thank you very much…

1 Like