Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created Dec 2, 2020
Embed
What would you like to do?
Codecademy export
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(appetizers){
return this._courses.appetizers
}, set mains(mains){
return this._courses.mains
}, set desserts(desserts){
return this._courses.desserts
}, 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 random = Math.floor(Math.random()*dishes.length);
return dishes [random];
},
getRandomMeal(){
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', 'g',20);
menu.addDishToCourse('appetizers', 'p',22);
menu.addDishToCourse('appetizers', 'm',21);
menu.addDishToCourse('appetizers', 'g',28);
menu.addDishToCourse('appetizers', 'g',27);
menu.addDishToCourse('appetizers', 'g',29);
menu.addDishToCourse('desserts', 'd',23);
menu.addDishToCourse('desserts', 'f',24);
menu.addDishToCourse('desserts', 'o',25);
let meal = menu.getRandomMeal();
console.log(meal);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment