Selecting from Many Options with Switch Statements: https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements

Tell us what’s happening:

Hey I posted my code in the title. Im not sure why my switch statements arent working. Thanks for your help!


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

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

Your browser information:

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

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

You are suppose to switch statement here you have used if else so non of the text is accepting
used switch case

something like that
switch(num) {
case value1:
statement1;
break;
case value2:
statement2;
break;

case valueN:
statementN;
break;
}

1 Like

You should use switch statement. The syntax goes like this.

switch(val) {
  case ... :
    variable assingment here
}

Go head and remove your if statements and replace them with cases. Also instead of writing down strings you should be assigning them to answer variable.

Don’t forget to add a default case too!

Good luck :slight_smile:

1 Like