Selecting from Many Options with Switch Statements (articulation)

Selecting from Many Options with Switch Statements (articulation)
0

#1

Tell us what’s happening:

can’t articulate a switch case properly

Your code so far


function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  caseInSwitch(1);
    "alpha";
  break;
  caseInSwitch(2);
    "beta";
  break;
  caseInSwitch(3);
    "gamma";
  break;
  caseInSwitch(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 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 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


#2

You are suppose to be using a single switch statement to test various cases of the val argument. The possible values of val would be handled by using the case keyword.

Instead, you have tried to call the function name several times in your code with various numbers. Look at the example code again. The general syntax will look like the following:

function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch(???) {
  case value1:
    statement1;
    break;
  case value2:
    statement2;
    break;
  case value3:
    statement3;
    break;
  case value4:
    statement4;
    break;
}
  // Only change code above this line  
  return answer;  
}

You get to figure out what to put for ??? and the value1, value2, value3, and value4 along with what the statement1, statement2, statement3, and statement4 should be.