0 javascript object javascript-objects
我从编码练习中得到以下代码.当我尝试提交它时,我得到了一个
SyntaxError:意外的字符串
var movieObj = {
"Toy Story 2": "Great story. Mean prospector.",
"Finding Nemo": "Cool animation, and funny turtles."
"The Lion King": "Great songs."
};
var getReview = function (movie) {
if (movie in movieObj) {
return movieObj[movie]
} else {
return "I don't know!"
}
};
getReview("Toy Story 2") //expected = "Great story. Mean prospector."
getReview("Toy Story") //expected = " don't know!"
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
你实际上只是错过了movieObj对象的第二项的逗号.用"Finding Nemo": "Cool animation, and funny turtles.",
/* Notice the comma */它取代第二行
它应该在那之后正常工作.
| 归档时间: |
|
| 查看次数: |
59 次 |
| 最近记录: |