The aim of this puzzle:
Find a syntax error and fix it. A syntax error is often incorrect or missing characters.
Walkthrough of the solution:
The starter code contains these lines:
let dinner = 'Dinner for Monday: ' + meals.mondey;
console.log(dinner);
They print the following:
Dinner for Monday: undefined
It prints undefined
because the code is trying to access the property mondey
in the meals
object. Here is the meals object:
let meals = {
monday: "curry",
tuesday: "soup",
wednesday: "rice",
};
The property in the meals
object the code is looking for is monday
. Since mondey
is spelled incorrectly, JavaScript returns undefined
. This happens when code tries to access a property or variable that does not exist or has not been defined.
In this case, the correct property is spelled monday
. To correct it, remove .mondey
, then replace it with .monday
.
Sample code solution:
(Tap below to reveal)
let meals = {
monday: "curry",
tuesday: "soup",
wednesday: "rice",
};
let dinner = 'Dinner for Monday: ' + meals.monday;
console.log(dinner);
JavaScript Concepts: undefined