我正在尝试运行此代码,但它给我一个错误,提示“输入意外结束”。你愿意帮忙吗?提前致谢。
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;
};
最佳答案
您的函数似乎缺少右大括号:
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
另请注意,在 return
后添加 break
或在 switch
block 末尾添加分号是没有意义的。您可以将上面的内容简化为:
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!";
}
};
关于JavaScript 切换函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28705577/