87,902
社区成员
发帖
与我相关
我的任务
分享
var getReview = function (movie) {
switch(movie){
case "Matrix": //case语法错误 而且字符串要用引号括起来。
return"good trip out";
case "Princess Bride":
return"awesome date night movie";
case "Welcome to America":
return"Amjad's favorite";
case "Remember the Titans":
return"love the sports";
case "Why do I look like I'm 12?":
return"The Ryan and Zach story";
case "Fighting Kangaroos in the wild":
return "Token Australian movie for Leng";
//fault //这里是不是拼写错误?
default :
return"I don't know!";
}
};
getReview("Matrix");
Way to go!
通过了,谢谢你哈
var getReview = function (movie) {
switch(movie){
case "Matrix": //case语法错误 而且字符串要用引号括起来。
return"good trip out";
case "Princess Bride":
return"awesome date night movie";
case "Welcome to America":
return"Amjad's favorite";
case "Remember the Titans":
return"love the sports";
case "Why do I look like I'm 12?":
return"The Ryan and Zach story";
case "Fighting Kangaroos in the wild":
return "Token Australian movie for Leng";
//fault //这里是不是拼写错误?
default :
return"I don't know!";
}
};
getReview("Matrix");
Way to go!
另,另一个方法没通过,但这代码明显更精减。
var getReview = function (movie) {
var movies= {
"Matrix":"good trip out",
"Princess Bride" : "awesome date night movie",
"Welcome to America" : "Amjad's favorite",
"Remember the Titans" : "love the sports",
"Why do I look like I'm 12?" : "The Ryan and Zach story",
"Fighting Kangaroos in the wild" : "Token Australian movie for Leng"
}
if(movie in movies){
return movies[movie];
}
return "I don't know!"
};
getReview("Matrix");
Oops, try again! Better use a switch statementvar getReview = function (movie) {
switch(movie){
case "Matrix":
console.log("good trip out");
break;
case "Princess Bride":
console.log("awesome date night movie");
break;
case "Welcome to America":
console.log("Amjad's favorite");
break;
case "Remember the Titans":
console.log("love the sports");
break;
case "Why do I look like I'm 12?":
console.log("The Ryan and Zach story");
break;
case"Fighting Kangaroos in the wild":
console.log("Token Australian movie for Leng");
break;
default:
console.log("I don't know!");
}
};
getReview("Fighting Kangaroos in the wild");
var getReview = function (movie) {
switch(movie){
case "Matrix": //case语法错误 而且字符串要用引号括起来。
return"good trip out";
case "Princess Bride":
return"awesome date night movie";
case "Welcome to America":
return"Amjad's favorite";
case "Remember the Titans":
return"love the sports";
case "Why do I look like":
return"The Ryan and Zach story";
case "Fighting Kangaroos in the wild":
return "Token Australian movie for Leng";
//fault //这里是不是拼写错误?
default :
return"I don't know!";
}
};