Meal maker project

I am stuck on this meal maker project in the object section of the javascript course. I keep getting this error /home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:37
return this._courses[courseName].push(dish);
^

TypeError: Cannot read property ‘push’ of undefined

Can someone please assist me.

My code is below.

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(appetizersIn) {

this._courses.appetizers = appetizersIn

},

set mains(mainsIn) {

this._courses.mains = mainsIn

},

set desserts(dessertsIn) {

this._courses.desserts = dessertsIn

},

get _courses() {

return {

  appetizers: this.appetizersIn,

  mains: this.mainsIn,

  desserts: this.dessertsIn

}

},

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 = getRandomDishFromCourse('appetizer');

const mains = getRandomDishFromCourse('main');

const desserts = getRandomDishFromCourse('dessert')

const totalPrice = appetizers.price + mains.pric + desserts.price ;

return `Your meal  is ${appetizers.name}, ${mains.name} with a dessert choice of ${desserts.name} and your total price is ${totalPrice}`;

},

};

menu.addDishToCourse(‘appetizer’, ‘fries’, 3.00);

menu.addDishToCourse(‘appetizer’, ‘cheese-sticks’, 5.00);

menu.addDishToCourse(‘appetizer’, ‘soup’, 5.00);

menu.addDishToCourse(‘main’, ‘steak’, 11.00);

menu.addDishToCourse(‘main’, ‘chicken’, 10.00);

menu.addDishToCourse(‘main’, ‘shrimp’, 12.50);

menu.addDishToCourse(‘dessert’, ‘cookie’, 2.00);

menu.addDishToCourse(‘dessert’, ‘ice cream’, 4.00);

menu.addDishToCourse(‘dessert’, ‘brownie’, 5.00);

Hi @data4998177506

That means this._courses[courseName] isn’t defined / doesn’t exist.
Add a console.log(courseName); to the function where the error is thrown and see what says. Then you can compare the output with the key name of the array you want to push to.

You can remove the return keyword, because the purpose of that function is to push to an array, not to return anything to a calling function.

Your getter for courses is overwriting the _courses object.

try logging both the this object and the this._courses inside the function with the error and you’ll see how its off. Fix the name of the getter function so it doesn’t conflict and they try again to see how the object looks different. That should help you move forward.