Meal Maker syntax problem (defining price)

Hello Codecademy forums!

I’m struggling to understand where I have gone wrong in accessing / assigning price, although I can see that I haven’t done this so understand why I’m recieving the error message 'TypeError: Cannot read property ‘price’ of undefined
at Object.generateRandomMeal ’

const menu = { _courses: { appetizers: [], mains: [], desserts: [] }, get courses() { return { appetizers: this.appetizers, mains: this.mains, desserts: this.desserts, } }, //below are the getter and setter methods for the appetizers, that allow the different appetizer inputs to be associated with the course property. get appetizers(){ return this.courses._appetizers }, set appetizers(appetizerChoice){}, get mains(){ return this.courses._mains }, set mains(mainsChoice){}, get desserts(){ return this.courses._desserts }, set desserts(dessertChoice){}, addDishToCourse(courseName, dishName, dishPice){ const dish ={ name: this.dishName, price: this.dishPrice }; this._courses[courseName].push(dish); }, getRandomDishFromCourse(courseName){ const dishes = this._courses[courseName]; const randomIndex = Math.floor(Math.random() * dishes.length); }, generateRandomMeal() { const appetizer = this.getRandomDishFromCourse('appetizers'); const main = 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 ${dessert.name}... The price is ${totalPrice}.`; } }; menu.addDishToCourse('appetizers', 'cesar salad', 3.00); menu.addDishToCourse('appetizers', 'Daal', 4.50); menu.addDishToCourse('appetizers', 'Bhaji', 1.00); menu.addDishToCourse('mains', 'Quinoa Big Salad', 12.00); menu.addDishToCourse('mains', 'Rice Noodles', 14.00); menu.addDishToCourse('mains', 'Stuffed Aubergine', 10.00); menu.addDishToCourse('desserts', 'Iced Cream', 4.00); menu.addDishToCourse('desserts', 'Jelly', 2.00); menu.addDishToCourse('desserts', 'Just Coffee', 5.00); let meal = menu.generateRandomMeal(); console.log(meal);

If anyone could help me to understand where I’m going wrong I’d really appreciate it, as I’ve been struggling my way through this project so might need to go back to review certain concepts again.:slight_smile:

Kindest, C :upside_down_face:

You try to access price here:

const totalPrice = appetizer.price + main.price + dessert.price

which is where you get the error. So where does the value for appetizer and other variable come from? getRandomDishFromCourse method, looking at this method:

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

I don’t see a return value?

So, to return the variables that are created in the getRandomDishFromCourse(), you would return something like ‘return dishes.randomIndex;’? How does this return the price value to the randomly generated dish? (sorry if this is a really silly question)

as the name of the getRandomDishFromCourse method suggest, this method should return a random dish

as you can see in the addDishToCourse method, each dish is an object with name and price property:

const dish ={
    name: this.dishName,
    price: this.dishPrice
};

you get the dishes from the course:

const dishes = this._courses[courseName];

and an a random index:

  const randomIndex = Math.floor(Math.random() * dishes.length);

but then you don’t use this random index to select and return a random dish from the dishes