Tell us what’s happening:
Hey-- have gone around and around with this one but still having a error-- could use some debug help-- here is my code:
function chainToSwitch(val) {
var answer = "";
// Only change code below this line
//////////////////////////////////////////////
switch(val){
case "bob":
answer = "Marley";
break;
case 42:
answer = "The Answer";
break;
case 1:
answer = "There is no #1";
break;
case 99:
answer = "Missed me by this much!";
break;
case 7:
answer = "Ate Nine";
break;
default:
answer= "Value not found!";
break;
/////////////////////////////////////////////
// Only change code above this line
}
// Change this value to test
chainToSwitch(7);
}
– && here is my error message:
// running tests
chainToSwitch("bob")
should be “Marley”
chainToSwitch(42)
should be “The Answer”
chainToSwitch(1)
should be “There is no #1”
chainToSwitch(99)
should be “Missed me by this much!”
chainToSwitch(7)
should be “Ate Nine”
chainToSwitch("John")
should be “” (empty string)
chainToSwitch(156)
should be “” (empty string) // tests completed
– would be grateful for any help at all && thanks.
Your code so far
function chainToSwitch(val) {
var answer = "";
// Only change code below this line
//////////////////////////////////////////////
switch(val){
case "bob":
answer = "Marley";
break;
case 42:
answer = "The Answer";
break;
case 1:
answer = "There is no #1";
break;
case 99:
answer = "Missed me by this much!";
break;
case 7:
answer = "Ate Nine";
break;
default:
answer= "Value not found!";
break;
/////////////////////////////////////////////
// Only change code above this line
}
// Change this value to test
chainToSwitch(7);
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36
.
Challenge: Replacing If Else Chains with Switch
Link to the challenge: