Meal Maker: Intro to JavaScript


#1

Hi, Been having issue with this project. The hints are a little confusing and there is no video for support. Any feedback would be appreciated. When I run it, it returns “undefined”. Not sure where my mistake is. Thanks

const menu = {
  _courses:{
    appetizers: [],
    mains: [],
    desserts: [],
    get courses(){
      return {
        appetizers: this._courses.apetizers, mains: this._courses.mains, desserts: this._courses.desserts

      }
      addDishToCourse (courseName, dishName, dishPrice)
        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)
          
        }
      generateRandomMeal()
 {
    const appetizer =
              this.getRandomDishFromCourse('appetizers')
        const mains =  this.getRandomDishFromCourse('mains')
        const desserts =  this.getRandomDishFromCourse('desserts')
        const totalPrice = appetizer.price + mains.price + desserts.price
        return `Your meal is a ${appetizer.name}, ${mains.name}, and ${desserts.name}. The price is $${totalPrice}.`
        menu.addDishToCourse('appetizers', 'Caesar Salad', 4.25)
        menu.addDishToCourse('appetizers', 'House Salad', 4.50)
        menu.addDishToCourse('appetizers', 'Chopped Salad', 4.15)
        menu.addDishToCourse('mains', 'Chicken Fingers', 6)
        menu.addDishToCourse('mains', 'Steak', 10)
        menu.addDishToCourse('mains', 'Lobster', 8)
        menu.addDishToCourse('desserts', 'Cookie', 4.45)
        menu.addDishToCourse('desserts', 'Chocolate Cake', 4.65)
        menu.addDishToCourse('desserts', 'Tiramisu', 5)
      }
      }
  }
}
let meal = menu.generateRandomMeal
console.log(meal)

#2

step 5 of the instructions:

Inside your menu object, create an empty getter method for the _courses property.

you created this getter method within the courses object. The courses getter method should be outside/after the _courses object.

this problem is re-occurring throughout your code. If you look here:

addDishToCourse (courseName, dishName, dishPrice)
        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)
          
        }

you nest the getRandomDishFromCourse method within the addDishToCourse method, why would you do that?

the getRandomDishFromCourse should be a method of menu object.


#3

Hi,

Thanks for that. That’s why I was confused. Where exactly should that getRandomDishFromCourse go? Way at the top? I wish there was a walk through video for this :confused:


#4

a walk through video won’t teach you the thinking steps required.

i would just place getRandomDishFromCourse after addDishToCourse. The most important thing is that both methods are property of menu object, which is currently not the case