Closed. This question is off-topic。它当前不接受答案。
想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
2年前关闭。
我仍然不明白为什么它无法实现。我正在上FreeCodeCamp课程,而我仍然坚持这一课程。我什至进入了源代码中寻找答案,但它仍然对我不起作用。
想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
2年前关闭。
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 = "not correct";
}
}
// Only change code above this line
return answer;
// Change this value to test
chainToSwitch(7);
我仍然不明白为什么它无法实现。我正在上FreeCodeCamp课程,而我仍然坚持这一课程。我什至进入了源代码中寻找答案,但它仍然对我不起作用。
最佳答案
您需要在函数内移动return
语句。
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 = "not correct";
}
return answer;
}
console.log(chainToSwitch(7));