Hello, I was following along the code but I keep getting this error message "maker/app.js:39
return this._courses[courseName].push(dish);
^
TypeError: Cannot read property ‘push’ of undefined
at Object.addDishToCourse"**
Can someone explain what I’m doing wrong here?
I keep looking through the code but I can’t figure out why the error keeps popping up!!! i think the error is in this function " addDishToCourse(courseName, dishName, dishPrice){
const dish = {
name: dishName,
price:dishPrice,
};
//property assignment first, then push the dish object into _courses
return this._courses[courseName].push(dish);
},"
THE COSDE IS BELLOW
const menu = {
//Create three properties inside the _courses object called appetizers, mains, and desserts. Each one of these should initialize to an empty array
_courses: {
appetizers: ,
mains: ,
desserts: ,
},
get appetizers(){
return this._courses.appetizers;
},
get mains(){
return this._courses.mains;
},
get desserts(){
return this._courses.desserts;
},
set appetizers(parameterOfAppetizers){
this._courses.appetizers= parameterOfAppetizers;
},
set mains(parameterOfMains){
this._courses.mains = parameterOfMains;
},
set desserts(parameterOfDesserts){
this._courses.desserts= parameterOfDesserts;
},
get courses(){
return{
appetizers: this.appetizers,
mains: this.mains,
desserts: this.desserts,
};
},
addDishToCourse(courseName, dishName, dishPrice){
-
const dish = {*
-
name: dishName,*
-
price:dishPrice,*
-
};*
-
//property assignment first, then push the dish object into _courses*
-
return this._courses[courseName].push(dish);*
- },*
// create a function that allow to get a random dish from a course on the menu, which will be necessary for generating a random meal.
getRandomDishFromCourse(courseName){
//Retrieve the array of the given course’s dishes from the menu‘s _courses
const dishes = this._courses[courseName];
const randomIndex =Math.floor(Math.random()* dishes.length);
return dishes[randomIndex];
},
//generate a three course meal
generateRandomMeal(){
const appetizer= this.getRandomDishFromCourse(‘appetizers’);
const main= this.getRandomDishFromCourse(‘mains’);
const dessert= this.getRandomDishFromCourse(‘desserts’);
//calculate total price
const totalprice = appetizer.price + main.price + dessert.price;
returnYour meal is ${appetizer.price}, ${main.price}, and ${dessert.price}, and the total price is ${totalprice}
;
}
};
//create the menu
menu.addDishToCourse(‘Appetizer’,“Salad”, 4);
menu.addDishToCourse(‘Appetizer’,“Soup”, 5.50);
menu.addDishToCourse(‘Appetizer’,“Fries”, 5);
menu.addDishToCourse(‘Mains’,“Salmon”, 10);
menu.addDishToCourse(‘Mains’,“Steak”, 14);
menu.addDishToCourse(‘Mains’,“Pizza”, 12);
menu.addDishToCourse(‘Desserts’,“Fruit_salad”, 4);
menu.addDishToCourse(‘Desserts’,“Ice_cream”, 5);
menu.addDishToCourse(‘Desserts’,“Frappe”, 4.50);
//generate random meal
const meal = menu.generateRandomMeal();
console.log(meal);