Meal Maker Project: Cannot read property 'push' of undefined

I’ve been working on the Meal Maker project in the JavaScript Objects section. For some reason, the .push() method keeps causing errors in my getters and the addDishToCourse() method.

I’ve read all of the threads related to this problem on Codecademy, but nothing seems to be working.

Here is my code: https://gist.github.com/abb2dbd65ccdcd363d583396aa255dcb

_appetizers (and _mains and _desserts) are properties of courses object, as such, the getter and setter methods for appetizers should be in the courses object:

  _courses: {
    _appetizers: [],
    _mains: [],
    _desserts: [],
    get appetizers(){
        return this._appetizers;
    }
  },

you can’t just return a string, the getters are used every time we try to read the property, the getter is used here:

this._courses[courseName].push(dish);

so you want the array, not some string

1 Like
this._courses[courseName].push(dish);

Since we’re calling the getter, we may as well call the setter, too.

this._courses[courseName] = dish;

The setter has its own push method call.

2 Likes

Thank you! Here’s my final code for anyone who has the same question in the future: https://gist.github.com/375a0e78d13c3bd0daaa8b2263693ed9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.