我正在尝试运行此代码,但它给出了一个错误,说“意外的输入结束”。你能帮忙吗?提前谢谢。
var getReview = function (movie) {
switch (movie) {
case "Toy Story 2":
return "Great story. Mean prospector.";
break;
case "Finding Nemo" :
return "Cool animation, and funny turtles.";
break;
case "The Lion King" :
return "Great songs.";
break;
default :
return "I dont know!";
break;
};
答案 0 :(得分:2)
您的功能似乎缺少结束括号:
var getReview = function (movie) {
switch (movie) {
case "Toy Story 2":
return "Great story. Mean prospector.";
break;
case "Finding Nemo" :
return "Cool animation, and funny turtles.";
break;
case "The Lion King" :
return "Great songs.";
break;
default :
return "I dont know!";
break;
};
}; // <-- here
另请注意,在break
块结尾处return
或分号后面switch
是没有意义的。您可以将上述内容减少到:
var getReview = function (movie) {
switch (movie) {
case "Toy Story 2":
return "Great story. Mean prospector.";
case "Finding Nemo" :
return "Cool animation, and funny turtles.";
case "The Lion King" :
return "Great songs.";
default :
return "I dont know!";
}
};