Skip to content

Instantly share code, notes, and snippets.

@codecademydev codecademydev/app.js Secret

Created Apr 8, 2019
Embed
What would you like to do?
Codecademy export
const menu = {
_courses: {
appetizers: [],
mains: [],
desserts: []
},
get courses() {
return {
appetizers: this.appetizers,
mains: this.mains,
desserts: this.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;
},
addDishToCourse(courseName, dishName, dishPrice) {
const dish = {
dish: 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];
},
generateRandomeMeal() {
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', 'soup', 4.50);
menu.addDishToCourse('appetizers', 'sashimi', 6.00);
menu.addDishToCourse('mains', 'fish', 12.00);
menu.addDishToCourse('mains', 'steak', 18.00);
menu.addDishToCourse('mains', 'pork', 14.00);
menu.addDishToCourse('desserts', 'cake', 6.00);
menu.addDishToCourse('desserts', 'icecream', 5.00);
menu.addDishToCourse('desserts', 'fruit', 4.00);
const meal = menu.generateRandomeMeal();
console.log(meal);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.