I keep getting the following error from my code in the Meal Maker project: Can someone please help me figure out how to fix this issue? Many thanks. Please find my code below.
/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:38
this._courses[courseName].push(dish);
^
TypeError: Cannot read property ‘push’ of undefined
Here is my code below. Also, find it at the following link: https://gist.github.com/7298d0931dd3951130d711886f06df0b
const menu = {
_courses: {
appetizers: ,
mains: ,
desserts: ,
get _courses() {
return {
appetizers: this.appetizers,
mains: this.mains,
desserts: this.desserts
}
},
get appetizers() {
return this._appetizers;
},
set appetizers(appetizersInput) {
this._appetizers = appetizersInput;
},
get mains() {
return this._mains;
},
set mains(mainsInput) {
this._mains = mainsInput;
},
get desserts() {
return this._desserts;
},
set desserts(dessertsInput) {
this._desserts = dessertsInput;
}
},
addDishToCourse(courseName, dishName, dishPrice) {
const dish = {
name: this._dishName,
price: this._dishPrice
}
this._courses[courseName].push(dish);
},
getRandomDishFromCourse(courseName) {
const dishes = this._courses[courseName];
const randomIndex = Math.floor(Math.random() * dishes.length);
return dishes[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 is ${appetizer.name} + ${main.name} + ${dessert.name} and your total price is ${totalPrice}.
}
}
menu.addDishToCourse(‘appetizers’, ‘Bruchetta’, 7.99);