Selecting from Many Options with Switch Statements, Help Please

What am I doing wrong here?
I’m aware that many people have encountered this issue before me, but since I’m using an array, I’m wondering if that has any effect on the error.

My code:


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


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

caseInSwitch(1);

The error:
caseInSwitch(1) should have a value of the string alpha.
caseInSwitch(2) should have a value of the string beta.
caseInSwitch(3) should have a value of the string gamma.
caseInSwitch(4) should have a value of the string delta.

Challenge: Selecting from Many Options with Switch Statements

Link to the challenge:

can you please post your code instead of a screenshot?

my bad, fixed it. I thought it would be easier to see both the code and the error if it were a screenshot.

switch check values with strict equality
1 === "1" is false

2 Likes

Oh wow yeah, I didn’t even consider that. Thank you.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.