Meal Maker - Help with push method error

Hello,

I’m trying to complete the Meal Maker project inside JavaScript Syntax Par II but I have run into an issue.

When I try to push the variable dish to courseName, I get this error: Cannot read property ‘push’ of undefined, which tells me that the parameter courseName is not defined. I have no clue how to solve this. Any suggestions?

addDishToCourse(courseName, dishName, dishPrice) {
    const dish = {
      name: dishName,
      price: dishPrice,
    };
    return this._courses[courseName].push(dish);
},

Hello,

Most likely this means that you’re calling it with a courseName that doesn’t match one of the properties of the _courses object. For example, if it’s called “desserts” inside _courses, then you’d need to call addDishToCourse with “desserts”. Calling it with “dessert”, “junkfood”, or anything else not defined in _courses, will return undefined, which doesn’t have a .push() method

1 Like

I solved it. I was missing an “s”. I was trying to call

menu.addDishToCourse('mains', 'Tacos de Jackfruit', 5.75);

but instead of ‘mains’ I had ‘main’…I hate these typos. Thanks a lot for the help!

1 Like