Skip to content

Instantly share code, notes, and snippets.

@codecademydev

codecademydev/app.js Secret

Created Dec 11, 2020
Embed
What would you like to do?
Codecademy export
const menu = {
_courses: {
appitizers: [],
mains: [],
desserts: []
},
get appitizers() {
return this._courses.appitizers;
},
get mains() {
return this._courses.mains;
},
get desserts() {
return this._courses.desserts;
},
set appitizers(appitizerIn){
this._courses.appitizers = appitizerIn;
},
set mains(mainIn){
this._courses.mains = mainIn;
},
set desserts(dessertIn){
this._courses.desserts = dessertIn;
},
get courses() {
return {
appitizers: this.appitizers,
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);
return dishes[randomIndex];
},
generateRandomMeal: function() {
const appitizer = this.getRandomDishFromCourse('appitizers');
const main = this.getRandomDishFromCourse('mains');
const dessert = this.getRandomDishFromCourse('desserts');
const totalPrice = appitizer.price + main.price + dessert.price;
return `Your meal includes: ${appitizer.name}, ${main.name} and ${dessert.name}. Total Cost: ${totalPrice}`
}
};
menu.addDishToCourse('appitizers', 'Cheese Board', 1.50);
menu.addDishToCourse('appitizers', 'Garlic Snails', 3);
menu.addDishToCourse('appitizers', 'Breaded Mushroom', 4.50);
menu.addDishToCourse('mains', 'NY Strip', 8.50);
menu.addDishToCourse('mains', 'Alfredo Pasta', 7);
menu.addDishToCourse('mains', 'Vegan Burger', 10);
menu.addDishToCourse('desserts', 'Nuetlla Orea Cheesecake', 5);
menu.addDishToCourse('desserts', 'Chocolate Taster', 6.50);
menu.addDishToCourse('desserts', 'Sorbet', 4.50);
const meal = menu.generateRandomMeal();
console.log(meal);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment