[英]console shows unexpected identifier error and the code doesnot run
var movies = [ {title: "Wolf of wall street",stars: 5, havewatched: false}, var movies = [ {title: "华尔街之狼",stars: 5, havewatched: false},
{title: "Mad max fury road", stars: 5, havewatched: true}, {标题:“疯狂的麦克斯狂暴之路”,星数:5,已观看:真实},
{title: "search party ", stars: 5, havewatched: false}, {title: "search party", stars: 5, havewatched: false},
{title: "brooklyn nine nine", stars: 5, havewatched: true} ] {标题:“布鲁克林九九”,星数:5,看过:真实}]
movies.forEach(function(movie){
var result = "You have" ;
if (movie.havewatched)
result += "watched" ;
}else {
result += "not watched";
}
result = result + movie.title + "-" + movie.stars ;
console.log(result)
})
Here is working code after fixing the missing {
in the if condition.这是修复 if 条件中缺少的{
后的工作代码。
var movies = [ {title: "Wolf of wall street",stars: 5, havewatched: false}, {title: "Mad max fury road", stars: 5, havewatched: true}, {title: "search party ", stars: 5, havewatched: false}, {title: "brooklyn nine nine", stars: 5, havewatched: true} ] movies.forEach(function(movie){ var result = "You have"; if (movie.havewatched){ result += "watched"; }else { result += "not watched"; } result = result + movie.title + "-" + movie.stars; console.log(result) })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.