Meal Maker

Hello all, I have been trying to solve this error for 2 days, and I just cant. I could use another pair of eyes because it feels like mine are just close :frowning: Thank you so much

my error is ----TypeError: Cannot read property ‘price’ of undefined
at Object.generateRandomMeal —

const menu = { 
  _courses: { 
    appetizers: [], 
    mains: [], 
    desserts: [],  
  }, 

set appetizers(appetizer) { 
  this.appetizers.push(appetizer); 
}, 
get appetizers() { 
  return this.appetizers; 
}, 
 
set mains(mains) { 
this.mains.push(mains); 
}, 
get mains() { 
return this.mains; 
},

set desserts(desserts) { 
this.desserts.push(desserts); 
}, 
get desserts() { 
return this.desserts; 
},
get courses() { 
  return { 
      appetizers: this._courses.appetizers,
      mains: this._courses.mains,
      desserts: this._courses.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.lentgth); 
  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 consists of: ${appetizer.name}, ${main.name} and for dessert, ${dessert.name}. The total price is ${totalPrice}.`
}, 
}; 

menu.addDishToCourse('appetizers', ' salad',  5); 
menu.addDishToCourse('appetizers', 'chicken salad', 2.30); 
menu.addDishToCourse('appetizers', 'wings', 10); 

menu.addDishToCourse('mains', 'fish', 30); 
menu.addDishToCourse('mains', 'linguini', 15.60); 
menu.addDishToCourse('mains', 'pizza', 12.30); 

menu.addDishToCourse('desserts', 'cake', 13.60); 
menu.addDishToCourse('desserts',  'ice cream', 10.50); 
menu.addDishToCourse('desserts', 'tapioca', 9.40); 

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

Hi @ardnael_chip73330771
welcome to the forum.
I haven’t checked all of your code, but your problem lies already within the method

Log your const randomIndex: Your method cannot return anything valid, because you have a typo in your const assignment. Therefore your generateRandomMeal doesn’t receive dishes.

Thnak you all!!! I saw the typo :joy: :joy: :joy: