-
-
Save codecademydev/ffd1510994befbb60c6387d8ff91d818 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const menu = { | |
_courses: { | |
appetizers: [], | |
mains: [], | |
desserts: [], | |
}, | |
get appetizers() { | |
return this._courses.appetizers; | |
}, | |
set appetizers(app) { | |
this._courses.appetizers = app; | |
}, | |
get mains() { | |
return this._courses.mains; | |
}, | |
set mains(entree) { | |
this._courses.mains = entree; | |
}, | |
get desserts() { | |
return this._courses.desserts; | |
}, | |
set desserts(sweets) { | |
this._courses.desserts = sweets; | |
}, | |
get courses() { | |
return { | |
appetizers: this.appetizers, | |
mains: this.mains, | |
desserts: this.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() { | |
let appetizer = | |
this.getRandomDishFromCourse('Appetizer'); | |
let mains = this.getRandomDishFromCourse('main'); | |
let desserts = | |
this.getRandomDishFronCourse('dessert'); | |
const totalPrice = appetizer.price + mains.price + desserts.price; | |
return 'Your meal is ' + appetizer.name + main.name + '. The price is $' + totalprice + '.'; | |
}, | |
}; | |
menu.addDishToCourse('appetizers', 'caesar salad', 5); | |
menu.addDishToCourse('mains', 'aguacate', 45); | |
menu.addDishToCourse('desserts', 'tecate', 100); | |
console.log(menu._courses); | |
let meal = menu.generateRandomMeal(); | |
console.log(meal); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment