Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created Sep 21, 2020
Embed
What would you like to do?
Codecademy export
const menu = {
_courses: {
appetizers: [],
mains: [],
desserts: [],
},
set appetizers(inAppetizers){
this._courses.appetizers = inAppetizers;
},
get appetizers(){
return this._courses.appetizers;
},
set mains(inMains){
this._courses.mains = inMains;
},
get mains() {
return this._courses.mains;
},
set desserts(inDesserts){
this._courses.desserts = inDesserts;
},
get desserts(){
return this._courses.desserts;
},
get courses() {
return {
appetizers: this.appetizers,
mains: this.mains,
desserts: this.desserts,
/*It could be
this._courses; for all os them
*/
}
},
addDishToCourse(courseName,dishName,dishPrice){
const dish = {
name: dishName,
price: dishPrice
};
//console.log(courseName, dish);
return this._courses[courseName].push(dish);
// Try using the setter methods
},
getRandomDishFromCourse: function(courseName){
const dishes = this._courses[courseName];
return (dishes[Math.floor(Math.random () * dishes.length)]);
},
generateRandomMeal: function (){
const appetizer = this.getRandomDishFromCourse('appetizers');
const main = this.getRandomDishFromCourse('mains');
const dessert = this.getRandomDishFromCourse('desserts');
const tPrice = appetizer.price + main.price + dessert.price;
return `This is the meal. Appetizer: ${appetizer.name}, Main: ${main.name} and Dessert: ${dessert.name}, for the total of $${tPrice}.`;
}
};
menu.addDishToCourse('appetizers','Hongos Salteados',100);
menu.addDishToCourse('appetizers','Ensalada',150);
menu.addDishToCourse('appetizers','Tapas',200);
menu.addDishToCourse('mains','Carne asada',300);
menu.addDishToCourse('mains','Pasta',250);
menu.addDishToCourse('mains','Mero',250);
menu.addDishToCourse('desserts','Pastel',150);
menu.addDishToCourse('desserts','Pan',150);
menu.addDishToCourse('desserts','Café',150);
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