Project Meal Maker

const menu = {
  _courses: {
     appetizers: [],
     mains: [],
     desserts: [],
  },
  get appetizers() {
    return this._courses.appetizers;
  },
  set appetizers(appetizers) {
    this._courses.appetizers = appetizers;
  },
  get mains() {
    return this._courses.mains;
  },
  set mains(mains) {
    this._courses.mains = mains;
  },
  get desserts() {
    return this._courses.desserts;
  },
  set desserts(desserts) {
    this._courses.desserts = desserts;
  },
  get courses() {
    return {
    appetizers: this.appetizers, 
    mains: this.mains, 
    desserts: this.desserts
    };
  },
  addDishToCourse(courseName, dishName, dishPrice) {
    const dish = {
      name: dishName,
      price: 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 appetizers = this.getRandomDishFromCourse('appetizers');
    const mains = this.getRandomDishFromCourse('mains');
    const desserts = this.getRandomDishFromCourse('desserts');
    const totalPrice = appetizers.price + mains.price + desserts.price;
    return `Your meal is ${appetizers.name}, ${mains.name} and ${desserts.name}. The price is ${totalPrice}.`;
  }
};
menu.addDishToCourse('appetizers', 'Salat Mewaee', 5.50);
menu.addDishToCourse('appetizers', 'Mast', 6);
menu.addDishToCourse('appetizers', 'Kachaloo', 1.5);
menu.addDishToCourse('mains', 'Qahwa', 3);
menu.addDishToCourse('mains', 'Sheer', 4);
menu.addDishToCourse('mains', 'Chai', 2.5);
menu.addDishToCourse('desserts', 'Freenee', 9);
menu.addDishToCourse('desserts', 'Kheer', 8);
menu.addDishToCourse('desserts', 'Mewa', 10);

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

Hello! Do you have a specific question regarding this code, or are you just sharing for some feedback?

To get feedback from fellow coders…

1 Like

Thanks for posting java0263087796. It helped me to compare against my project and figure out where I went wrong.

Happy Coding!

Scott

1 Like