Meal Maker issues

I can’t seem to get this code to work and I can’t find where I may have messed up! I keep getting "TypeError: Cannot read property ‘push’ of undefined at Object.addDishToCourse (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:31:33). Can anyone please help me? Thanks!

const menu = {
  _courses: {
    appetizers: [],
    mains: [],
    desserts: [],
  get courses() {
      appetizers: this.appetizers,
      mains: this.mains,
      desserts: this.desserts,
 get appetizers() {},
 set appetizers(appetizersCourse) {},
 get mains() {},
 set mains(mainsCourse) {},
 get desserts() {},
 set desserts(dessertsCourse) {},
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('appetizers');
    const main = this.getRandomDishFromCourse('mains');
    const dessert = this.getRandomDishFromCourse('desserts');
    const totalPrice = appetizer.price + main.price + dessert.price;
    return `Your meal is ${}, ${}, and ${}. Your total price is ${totalPrice}.`

menu.addDishToCourse('appetizer', 'wings', 8.00);
menu.addDishToCourse('appetizer', 'salad', 5.00);
menu.addDishToCourse('appetizer', 'soup', 4.75);

menu.addDishToCourse('main', 'burger', 12.00);
menu.addDishToCourse('main', 'pizza', 10.50);
menu.addDishToCourse('main', 'steak', 14.00);

menu.addDishToCourse('dessert', 'pie', 4.50);
menu.addDishToCourse('dessert', 'cheesecake', 5.00);
menu.addDishToCourse('dessert', 'ice cream', 3.00);

const meal = menu.generateRandomMeal();


I often find this error comes when there is a lot of code written before components are fully tested.

One strategy is to trace the route of what push() is actually asking. Once the route is traced, you can check each waypoint along the way to see that its state is what you really intended.

For example, if you determine your error is triggered in this line:
return this._courses[courseName].push(dish);, what can you track in the console?

You might track courseName (and maybe dish) for every possible expected value.

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