Meal maker

Hello everyone, I am working on meal maker right now. I finished it, however, when I try to run the code it always says
/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:37
this._courses[courseName].push(dish);
^

TypeError: Cannot read property ‘push’ of undefined

Does anyone know why this is happening?
This is my code

const menu = {
_courses: {
appetizers: ,
mains: ,
desserts:
},
get appetizers() {
return this._courses.appetizers;
},
get mains() {
return this._courses.mains;
},
get desserts() {
return this._courses.desserts;
},
set appetizers(appetizers) {
return this._courses.appetizers = appetizers;
},
set mains(mains) {
return this._courses.mains = mains;
},
set appetizers(desserts) {
return this._courses.desserts = desserts;
},
get courses() {
return {
appetizers: this.appetizers,
mains: this.mains,
desserts: this.desserts
}
},
addDishToCourse(courseName, dishName, dishPrice) {
const dish = {
name: dishName,
price: dishPrice
};
this._courses[courseName].push(dish);
},
getRandomDishFromCourse(courseName) {
const dishes = this._courses[courseName];
const randomNumber = Math.floor(Math.random() * dishes.length);
return dishes[randomNumber];
},
generateRandomMeal() {
const appetizer = this.getRandomDishFromCourse(‘appetizers’);
const main = this.getRandomDishFromCourse(‘mains’);
const dessert = this.getRandomDishFromCourse(‘desserts’);
const totalPrice = appetizer.price + main.price + dessert.price;
return Your appetizer is ${ appetizer.name }, your mains ${ main.name } and your dessert is ${ dessert.name }.The total price is ${ totalPrice };
}
};

menu.addDishToCourse(‘appetizers, calamari’, 10.00)
menu.addDishToCourse(‘appetizers, salad’, 5.00)
menu.addDishToCourse(‘appetizers, bread’, 4.00)

menu.addDishToCourse(‘mains, steak’, 30.00)
menu.addDishToCourse(‘mains, salmon’, 35.00)
menu.addDishToCourse(‘mains, burger’, 25.00)

menu.addDishToCourse(‘desserts, cupcake’, 9.00)
menu.addDishToCourse(‘desserts, cake’, 20.00)
menu.addDishToCourse(‘desserts, ice cream’, 5.00)

const meal = generateRandomMeal();
console.log(meal)

Oh, but did you? Finished does imply that it works. Just saying.

There are working parts to this program that need to be certified. In the process of debugging we begin by testing at the bare minimum level and work up from there. Have at it. Let us know how you are making out.

menu.courses

This should give you valid output when you log it if the ‘courses’ getter is written correctly.

appetizers: [],
mains: [],
desserts: []

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.