Meal Maker - referencing properties within methods

Hey all,

I’ve been working on the Meal Maker assignment and I think I have a good understanding of some of the previous concepts we’ve used in the lessons.

The only part of the assignment I can’t seem to wrap my head around is part 11.
How does this work?

const totalPrice = appetizer.price + main.price + dessert.price
return `You ordered ${}, ${} and ${}. Your total price is $${totalPrice}.`

How are we able to access price and name using the course choices (i.e appetizers, mains, desserts)?

Any help is appreciated, thank you!

you made a method called getRandomDishFromCourse, this is the method you are using (I assume, given you didn’t include this part of your code)

getRandomDishFromCourse returns an object containing price and name property, which is randomly retrieved from the corresponding course.

Hey thanks for the response!

That makes more sense, but just to clarify, when we use “appetizer.price” or “” are we able to use those values because of the get methods we had created at the beginning of the assignment?

Please include your full code or a link to the exercise

no, has nothing to do with the getter. Has to do with your getRandomDishFromCourse method, which returns an object containing these properties

I get what you are saying, its based off the courseName parameter that we pass into the function and it will randomly pick one of the three options in the program.

const menu = {
  _courses: {
    appetizers: [],
    mains: [],
    desserts: []
  get appetizers() {},
  set appetizers(aChoice) {},
  get mains() {},
  set mains(mChoice) {},
  get desserts() {},
  set desserts(dChoice) {},
  get courses() {
    return {
      appetizers: this.appetizers,
      mains: this.mains,
      desserts: this.desserts
  addDishToCourse(courseName, dishName, dishPrice) {
    const dish = {
      name: dishName,
      price: dishPrice
  getRandomDishFromCourse(courseName) {
    const dishes = this._courses[courseName]
    const randomDish = Math.floor(Math.random() * dishes.length)
    return dishes[randomDish]
  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 `You ordered ${}, ${} and ${}. Your total price is $${totalPrice}.`

menu.addDishToCourse('appetizers', 'A1', 5);
menu.addDishToCourse('appetizers', 'A2', 10);
menu.addDishToCourse('appetizers', 'A3', 15);

menu.addDishToCourse('mains', 'M1', 6);
menu.addDishToCourse('mains', 'M2', 12);
menu.addDishToCourse('mains', 'M3', 18);

menu.addDishToCourse('desserts', 'D1', 7);
menu.addDishToCourse('desserts', 'D2', 14);
menu.addDishToCourse('desserts', 'D3', 21);

const meal = menu.generateRandomMeal()

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.