What is wrong with my code for the 'Meal Maker' task?

Hey everyone, I’ve just gone through the ‘Meal Maker’ JavaScript Syntax 2 task, and I can’t for the life of me figure out what has gone wrong with my code! Even the walkthrough doesn’t seem to be of help! It keeps returning “TypeError: cannot read property ‘price’ of undefined at Object.generateRandomMeal”.

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(appetizers) {
      this._courses.appetizers = appetizers;
  },  set mains(mains) {
      this._courses.mains = mains;
  },  set desserts(desserts) {
      this._courses.desserts = desserts;
  
  }, 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) {
      const dishes = this._courses[courseName];
      const randomIndex = Math.floor(Math.random() * dishes.length);
      return dishes[randomIndex];
  
  }, generateRandomMeal() {
      const appetizer = this.getRandomDishFromCourse('appetizers');
      const mains = this.getRandomDishFromCourse('mains');
      const desserts = this.getRandomDishFromCourse('desserts');
      const totalPrice = appetizer.price + main.price + dessert.price;
      return `Your meal is ${appetizer.name}, ${main.name}, and the total price is ${totalPrice}!`;}
};

menu.addDishToCourse('appetizers', 'salad', 4.00);
menu.addDishToCourse('appetizers', 'garlic bread', 4.80);
menu.addDishToCourse('appetizers', 'soup', 4.30);

menu.addDishToCourse('mains', 'fish and chips', 13.75);
menu.addDishToCourse('mains', 'beef wellington', 15.00);
menu.addDishToCourse('mains', 'spaghetti bolognese', 12.50);

menu.addDishToCourse('desserts', 'brownie and ice cream', 9.00);
menu.addDishToCourse('desserts', 'sundae', 6.99);
menu.addDishToCourse('desserts', 'churros', 7.50);

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

you could debug your code, the error indicate that here:

const appetizer = this.getRandomDishFromCourse('appetizers');

appetizer is undefined, so there could be a problem with your getRandomDishFromCourse method, so we can add some logs to output some useful information for debugging:

getRandomDishFromCourse(courseName) {
      const dishes = this._courses[courseName];
      const randomIndex = Math.floor(Math.random() * dishes.length);
      console.log(dishes, randomIndex);
      return dishes[randomIndex];
  
  },

if you add the console.log() like I did, and then run your code, you will see there are no dishes.

Which means there is a problem with adding adding dishes to your courses

I noticed some minor typos in here:

const totalPrice = appetizer.price + main.price + dessert.price;
return `Your meal is ${appetizer.name}, ${main.name}, and the total price is ${totalPrice}!`; }

you used mains as the variable earlier in the function so main should be mains
you used desserts as the variable earlier in the function so dessert should be desserts
also, you forgot to put desserts.name on that second line.