Need help on Meal maker

Hi,

Im stuck on the meal maker project and I found i had to pretty much follow the tutorial all the way through. I knew what i was doing at first but sometimes got the syntax slightly wrong.

At the moment I am getting an error relating to the appetizer.price section, please can anyone provide any hints?

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

  return this._courses.appetizers = appetizers

},

  set mains (mains){

  return this._courses.mains = mains

},

set desserts (desserts){

  return this._courses.desserts = desserts

},

get course() {

return {

  appetizers : this.appetizers,

  mains: this.mains,

  dessert: this.dessert,

};

},

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.random(Math.floor() * 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 ${appetizer.name}, ${main.name} and ${dessert.name} and the total price is ${totalPrice}`;

}

};

menu.addDishToCourse("appetizers", "fries", 1);

menu.addDishToCourse("appetizers","carrot bag", 1);

menu.addDishToCourse("appetizers", "Mozzerlla sticks", 1.50);

menu.addDishToCourse("mains", "Big Mac", 3.49);

menu.addDishToCourse("mains","McNuggets", 2.99);

menu.addDishToCourse("mains", "Big Tasty", 4.35);

menu.addDishToCourse("desserts", "Crunchie Mcflurry", 1);

menu.addDishToCourse("desserts","Galaxy Mcflurry", 1);

menu.addDishToCourse("desserts", "Apple pie", 1.50);

const meal = menu.generateRandomMeal();

console.log(meal);

ERROR IS BELOW :

const totalPrice = appetizer.price + mains.price + desserts.price;
^

TypeError: Cannot read property ‘price’ of undefined

We could simply log some information to the console to see where the undefined comes from:

console.log(appetizer, main, dessert);
const totalPrice = appetizer.price + main.price + dessert.price;

which suggest something goes wrong in generateRandomMeal. Now you try :slight_smile: What would you log within the generateRandomMeal function? Go try, and tell me what you did when you get stuck :slight_smile: