Can someone help me understand why I am getting the unexpected result "6 You have not watched undefined undefined" in the browser console when running this simple code?
var films = [{
title: "The Mummy",
hasWatched: true,
stars: "5 stars"
},
{
title: "About A Boy",
hasWatched: true,
stars: "5 stars"
},
{
title: "It",
hasWatched: false,
stars: "5 stars"
},
{
title: "Cleopatra",
hasWatched: false,
stars: "5 stars"
}
];
for (var i = 0; i <= films.length; i++) {
if (films.hasWatched) {
console.log("You have watched " + films.title + " " + films.stars + ".");
} else {
console.log("You have not watched " + films.title + " " + films.stars + ".");
}
}