Please help: selecting from Many Options with Switch Statements

Please help: selecting from Many Options with Switch Statements
0

#1

Tell us what’s happening:
I’m trying to write a switch code but it doesn’t work for some reason. Can anyone explain to me why?

Your code so far


function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  
  switch(val) {
    case 1:
    "alpha";
    break;

    case 2:
    "beta";
    break;

    case 3:
    "gamma";
    break;

    case 4:
    "delta";
    break;
  }
  
  // Only change code above this line  
  return answer;  
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.75 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

In the above code they initialize a variable called answer. You need to set answer for each case. So case:1
answer =“alpha”;
Break;

Answer is going to be returned depending on what case


#3

function caseInSwitch(val) {
var answer = “”;
// Only change code below this line
switch (val){
case 1:
answer = “alpha”;
break;

case 2:
answer = "beta";
break;

case 3:
answer = "gamma";
break;

case 4:
answer = "delta";
break;

}

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

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

So, this is my new code and it passed the challenge test. It all looked similar to me until I realized that the answer variable had to be worked into the switch statement. That way, [val] in the function can be used in order to return the [answer] variable from the switch. Thank you!