Meal Maker

Hello everyone!! I can’t get the code run! It gives me an undefined error when I declare the price property!

const menu = {
  _courses: {
    appetizers:[],
    mains:[],
    desserts:[]
  },

  getRandomDishFromCourse(courseName) {
    const dishes = this._courses[courseName];
    const randomIndex = Math.floor(Math.random() * dishes.lenght);
    return dishes[randomIndex];
  },
  get appetizers(){
    return this._courses.appetizers;
  },
  get mains(){
    return this._courses.mains;
  },
  get desserts(){
    return this._courses.desserts;
  },
  set appetizers(appetizers) {
    this._courses.appetizers = appetizers;
  },
  set mains(mains) {
    this._courses.mains = mains;
  },
  set desserts(desserts) {
    this._courses.desserts = desserts;
  },
  get courses() {
    return {
      appetizers: this.appetizers,
      menus: this.menus,
      desserts: this.desserts,
    }
  },
    addDishToCourse(courseName, dishName, dishPrice){
    const dish = {
      name: dishName,
      price: dishPrice,
    }
    this._courses[courseName].push(dish);
  },
  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', 'salad', 4.00);
menu.addDishToCourse('appetizers', 'fries', 4.50);
menu.addDishToCourse('appetizers', 'wings', 5.00);

menu.addDishToCourse('mains', 'asado', 12.00);
menu.addDishToCourse('mains', 'ravioles', 8.00);
menu.addDishToCourse('mains', 'chicken breast', 10.00);

menu.addDishToCourse('desserts', 'ice cream', 3.00);
menu.addDishToCourse('desserts', 'fruits', 2.50);
menu.addDishToCourse('desserts', 'cheese cake', 5.00);

const meal = menu.generateRandomMeal();

You have a typo on line 10:

const randomIndex = Math.floor(Math.random() * dishes.lenght);
1 Like