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: