I wonder what is wrong with this code. There is no if else statements any more but it still warns that it’s wrong.
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=“default”;
break;
}
// Only change code above this line
return answer;
}
// Change this value to test
chainToSwitch(100);
Edit: I realized what is wrong. The numbers should be without " ". And nine should be written with big N.
function chainToSwitch(val) {
var answer = “”;
// Only change code below this line
switch (val) {
case “bob”:
return “Marley”;
break;
case 42:
return “The Answer”;
break;
case 1:
return “There is no #1”;
break;
case 99:
return “Missed me by this much!”;
break;
case 7:
return “Ate Nine”;
default:
}
// Only change code above this line
return answer;
}
// Change this value to test
chainToSwitch(“bob”);
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:
}
// Only change code above this line
return answer;
}
I’m having problem with Replacing If/Else Chain with Switch because I’m keep having an error about chainToSwitch(7). I got print, “Ate Nine”, but it won’t allow me to move to next challenge.
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 = "";
}
// Only change code above this line
return answer;
}
It is because you have ‘nine’, not ‘Nine’. These challenges often require that you have the exact answer it is looking for – including case. So just make the ‘n’ in nine uppercase, and it should work,
Hi Everyone.
The error is with the curly bracket “{}”.
You all included a curly bracket before the final return value.
Take the first closing curly bracket between your final break and return, then place it after chainToSwitch(100);.
It worked for me