Issue with Pushing to array [Meal Maker Project]

Here’s my code, following this tutorial Javascript Project Meal Maker - YouTube

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){ this._courses.appetizers = appetizers; }, set mains(mains){ this._courses.mains = mains; }, set desserts(desserts) { this._courses.desserts = appetizers; }, get courses(){ return { appetisers: this.appetisers, 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 dishes[randomIndex]; }, generateRandomMeal(){ const appetizer = this.getRandomDishFromCourse('appetisers'); const main = this.getRandomDishFromCourse('mains'); const dessert = this.getRandomDishFromCourse('desserts'); const totalPrice = appetiser.price + main.price + dessert.price; return `Your meal is ${appetiser.name}, ${main.name}, and ${dessert.name} and the total price is ${totalPrice}`; } }; //Test: menu.addDishToCourse('appetisers', 'cobb salad', 5.99); menu.addDishToCourse('appetisers', 'wings', 12.50); menu.addDishToCourse('appetisers', 'fries', 8.10); menu.addDishToCourse('mains', 'lobster noodles', 55.90); menu.addDishToCourse('mains', 'steak', 32.50); menu.addDishToCourse('mains', 'fried fish', 18.90); menu.addDishToCourse('desserts', 'sorbet', 5.50); menu.addDishToCourse('desserts', 'cake', 9.00); menu.addDishToCourse('desserts', 'cupcake', 4.00); const meal = menu.generateRandom(); console.log(menu);

I’m getting issues with the push, though!

/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:45
return this._courses[courseName].push(dish);
^

TypeError: Cannot read property ‘push’ of undefined

I’m wondering if anyone can help me out here?

Hi,
your issue is that this:

this._courses[courseName]

at the addDishToCourse method is undefined. So the push method does not know where to push to.
It has to match with the properties at this object:

_courses: {
  appetizers: [],
  mains: [],
  desserts: [],
}

Add a console.log(courseName) at the top of the method to see what you get there. If you replace [courseName] with the values logged in the console – doe that match with the _courses properties?