Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.9 kB
3
Indexable
Never
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 (appetizer) {
    this._courses.appetizers = appetizer
  },
  set mains (main) {
    this._courses.mains = main
  },
  set desserts (dessert) {
    this._courses.desserts = dessert
  },
  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) {
    let dishes = this._courses[courseName]
    const randomNumber = Math.floor(Math.random() * dishes.length)
    return 
    dishes[randomNumber]
  
  },
  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 `Let's eat ${appetizer.name}, ${main.name}, ${dessert.name}. You'll pay ${totalPrice}`
  }
}
menu.addDishToCourse('appetizers', 'Caesar Salad', 4.25)
menu.addDishToCourse('appetizers', 'Salami Salad', 5.25)
menu.addDishToCourse('appetizers', 'Chicken Salad', 5.25)
menu.addDishToCourse('mains', 'Chicken with fries', 9.25)
menu.addDishToCourse('mains', 'Pancakes', 6.25)
menu.addDishToCourse('mains', 'Pasta italiana', 9.25)
menu.addDishToCourse('desserts', 'tiramisu', 5.25)
menu.addDishToCourse('desserts', 'panna cotta', 4.25)
menu.addDishToCourse('desserts', 'ice cream', 4.25)

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