I’m tackling the Meal Maker project in the Intro to Javascript course and I cannot figure out why I keep getting the following error: “TypeError: Cannot read property ‘push’ of undefined at Object.addDishToCourse”. I’ve checked for spelling, commas, and other possible errors, but I can’t find anything. Here is my code:
const menu = {
_courses: {
appetizers: [],
mains: [],
desserts: [],
get appetizers() {
return this._courses.appetizers;
},
set appetizers(appetizers){
this._courses.appetizers = appetizers;
},
get mains() {
return this._courses.mains;
},
set mains(mains){
this._courses.mains = mains;
},
get desserts() {
return this._courses.appetizers;
},
set desserts(desserts){
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
};
return this._courses[courseName].push(dish);
},
getRandomDishFromCourse (courseName) {
const dishes = this._courses[courseName];
const randomIndex = Math.floor(Math.random() * dishes.length);
return randomIndex;
},
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 meal will begin with ${appetizer.name} followed by our main course of ${main.name}, and your meal will conclude with ${dessert.name} prepared to order. The meal will be ${totalPrice} dollars in total. Thank you and have a wonderful evening.`
}
};
menu.addDishToCourse('appetizers', 'spring rolls', 7);
menu.addDishToCourse('appetizers', 'cheese plate', 10);
menu.addDishToCourse('appetizers', 'kalamari', 9);
menu.addDishToCourse('mains', 'braised quail', 20);
menu.addDishToCourse('mains', 'poached salmon', 25);
menu.addDishToCourse('mains', 'fennel bulb and peccorino quiche', 17);
menu.addDishToCourse('desserts', 'flourless chocolate cake', 10);
menu.addDishToCourse('desserts', 'pineapple flan', 11);
menu.addDishToCourse('desserts', 'créme bruleé', 12);
Thank you! The link to the project is below.
https://www.codecademy.com/courses/introduction-to-javascript/projects/meal-maker