Hello, I do not know what is wrong with 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.desserts;
},
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){
let dishes = this._courses[courseName];
let randomIndex = Math.floor(Math.random() * dishes.length);
return dishes[randomIndex];
},
generateRandomMeal(){
const appetizer = this.getRandomDishFromCourse('appetizers');
const main = this.getRandomDishFromCourse('main');
const dessert = this.getRandomDishFromCourse('dessert');
}
}
menu.addDishToCourse('dessert', 'Bingsu', 5.90);
This is the error in the console:
/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:41
return this._courses[courseName].push(dish);
^
TypeError: Cannot read property 'push' of undefined
at Object.addDishToCourse (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:41:37)
at Object.<anonymous> (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:65:8)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)