Google说该代码无效,我的错误在哪里?

时间:2018-07-01 04:20:42

标签: javascript

var movie = [
    {
      title: "Iron Man",
      hasWatched: true,
      rating: "5.0",
    },
    {
      title: "Mad Max",
      hasWatched: false,
      rating: "2.0",
    }
]

Google表示无法在以下代码块中读取hasWatched属性

function buildString (movie){
    var result = "You have ";
    if(movie.hasWatched){ 
        result += "watched ";
    } else {
        result += "not watched ";
    }
    result += "\"" + movie.title + "\" - ";
    result += movie.rating + " stars"
    return result;
}

movie.forEach(function(movie){
    buildString();
    console.log(buildString(movie));
});

1 个答案:

答案 0 :(得分:0)

movie.forEach(function(movie){
buildString(movie);
console.log(buildString(movie));
});
  

您错过了将参数传递给buildString()函数。