Selecting from many options with Switch Statements--can't understand how to get the answer

Selecting from many options with Switch Statements--can't understand how to get the answer
0

#1

Hi, this is my code:

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

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

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

It’s not passing and I cannot understand how to get the answer. What is the answer? Can someone give me the answer to this problem? Thanks


#2

You are not returning anything.


#3

Can you write out the code so that it’s more understandable to me? Thanks.


#4

You should modify answer. If you get 1 as input you should set answer to ‘alpha’, if 2 to beta etc.


#5

Sorry, I need someone to write out the code. That’s the only way I can truly understand. I don’t understand what you’re explaining.


#6

deleted See below for correct response


#7

I tried that and it still doesn’t pass.


#8

Oh, sorry, I had to go back and look at the challenge; I had forgotten how it worked! Case 1 should return “alpha”. You will need to change your code in the switch(val) to set the answer to “alpha” if the case is 1, and so on. Hope that helps!


#9

I changed it to this but I still get 3 yellow triangles as errors:

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;
default:

// Only change code above this line
return answer;
}
}
// Change this value to test
caseInSwitch(1);


#10

You can ignore yellow triangles. They are warnings not errors.

If you like, you can remove break; from your code, because you use return.


#11

This is how I did the problem. A few different ways to solve, but this solution helps the answer make more sense I believe. You have to remember the end goal is getting the answer to return something. Have to make sure it is getting stored to answer.

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;

default:

}

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