Hello ,can anyone help me to find what's the problem with this code,( TypeError: Cannot read property 'price' of undefined)

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) {

    return

    const dish = {

      name: dishName,

      price: dishPrice,

   };

    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 Order is ${appetizer.name + main.name} and ${dessert.name},

and the total price is ${totalPrice} `;

  },

};

menu.addDishToCourse(‘appetizers’, ‘salad’, 4.00);

menu.addDishToCourse(‘appetizers’, ‘chicken wings’, 6.00);

menu.addDishToCourse(‘appetizers’, ‘chips’, 2.00);

menu.addDishToCourse(‘mains’, ‘Beaf steak’, 4.00);

menu.addDishToCourse(‘mains’, ‘Burger’, 6.00);

menu.addDishToCourse(‘mains’, ‘Lasagna’, 2.00);

menu.addDishToCourse(‘desserts’, ‘Ice Cream’, 4.00);

menu.addDishToCourse(‘desserts’, ‘Pana Cota’, 6.00);

menu.addDishToCourse(‘desserts’, ‘Tiramisu’, 2.00);

const meal = menu.generateRandomMeal();

console.log(meal);

Hi @text3514535778
Welcome to the forums!

If you log any of your courses, you’ll see that they are empty. Your dishes are never pushed to the courses object because the program never gets to the line where you push the dishes. You are leaving the method addDishToCourse before it does anything due to the return keyword.