Meal Maker - "Cannot read property 'appetizers' of undefined"

Below is my code.

const menu = {
  _courses: {
    // maps each course and the dishes available under that course
    appetizers: [],
    get appetizers(){
      return this._courses.appetizers;
    },
    set appetizers(appetizerDish){
      this._courses.mains = appetizerDish;
    },
    mains: [],
    get mains(){
      return this._courses.mains;
    },
    set mains(mainDish){
      this._courses.mains = mainDish;
    },
    desserts: [],
    get desserts(){
      return this._courses.desserts;
    },
    set desserts(dessertDish){
      this._courses.mains = dessertDish;
    },
  },
  
  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];
    return dishes[Math.floor(Math.random() * dishes.length)]
  },
  
  generateRandomMeal () {
    let appetizer = this.getRandomDishFromCourse('appetizers');
    let main = this.getRandomDishFromCourse('mains');
    let dessert = this.getRandomDishFromCourse('desserts');
    let totalPrice = appetizer.price + main.price + dessert.price;
    return `Order ${appetizer.name}, ${main.name} and ${dessert.name} for Rs.${totalPrice}.`
  }
  
};

menu.addDishToCourse('appetizers', 'Honey Chilli Potatos', 180);
menu.addDishToCourse('appetizers', 'Garlic Spinach Mushrooms', 220);
menu.addDishToCourse('appetizers', 'Coriander Cheese Momos', 200);

menu.addDishToCourse('mains', 'Aglio Olio Pasta', 280);
menu.addDishToCourse('mains', 'Thukpa', 240);
menu.addDishToCourse('mains', 'Fing with Tingmo', 260);

menu.addDishToCourse('desserts', 'Apple Pie', 230);
menu.addDishToCourse('desserts', 'Chocolate Mousse', 200);
menu.addDishToCourse('desserts', 'Newyork Cheesecake', 280);

const meal = menu.generateRandomMeal();
console.log(meal);

I get this error when I try to run it:

home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:6
      return this._courses.appetizers;
                          ^

TypeError: Cannot read property 'appetizers' of undefined
    at Object.get appetizers [as appetizers] (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:6:27)
    at Object.addDishToCourse (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:38:25)
    at Object.<anonymous> (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:53:6)
    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)

I figured there must be something causing the meals to not get added to the empty array, but for the life of me I cannot figure out why that is.

Since you have an error showing you that you’re trying to do something with undefined, either it was supposed to be some other value and then you’d look at the code that was supposed to create it, or you’re using the wrong thing altogether and should use something else.

If you sit down and crash as there is no chair there, then either put a chair there first or go sit somewhere where there is a chair, or don’t sit at all.

console.log(x) // nobody created x, create it or don't use it