Meal Maker - undefined arrays

Hi,

When I am printing out the solution, the arrays aren’t working. Not sure whether the dishes are being added properly or not. There’s no errors on my screen either.

const 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(appetizerIn){
    this._courses.appetizers = appetizerIn;
  },
  set mains(mainsIn){
    this._courses.mains = mainsIn;
  },
  set desserts(dessertsIn){
    this._courses.desserts = dessertsIn;
  },
  get courses() {
    return {
      appetizers: this.appetizers,
      mains: this.mains,
      desserts: this.desserts,
    }
  },
 
  addDishToCourse (courseName, dishName, dishPrice) {
    const dish = {
      name: this.dishName,
      price: this.dishPrice,
    };
    return this._courses[courseName].push(dish);
  },

  getRandomDishFromCourse(courseName){
    const dishes = this._courses[courseName];
    const randomIndex = Math.floor(Math.random() * 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}, ${dessert.name}. The price is $${totalPrice}.`;
  },
};

menu.addDishToCourse('appetizers', 'Seaweed Soup', 8.00);
menu.addDishToCourse('appetizers', 'Tomato Soup', 8.00);
menu.addDishToCourse('appetizers', 'Vegetable Soup', 8.00);

menu.addDishToCourse('mains', 'Steak', 28.00);
menu.addDishToCourse('mains', 'Yakisoba', 14.00);
menu.addDishToCourse('mains', 'Hotpot', 30.00);

menu.addDishToCourse('desserts', 'Custard Pudding', 6.50);
menu.addDishToCourse('desserts', 'Date Pudding', 7.80);
menu.addDishToCourse('desserts', 'Cookies and Tea', 5.60);

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

I see a problem here:

The parameters to that function are courseName, dishName, dishPrice
so
this.dishName should be dishName
this.dishPrice should be dishPrice
(that’s becuase this.dishPrice did’t exist yet, so it would show up as undefined )

1 Like

thanks for the quick reply! I like how simple your explanation was too.
It makes sense that ‘this.dishName’ wouldn’t exist if it’s being added. Thanks so much!