Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created October 30, 2020 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/76685d2b6ae00fd8fc672412c320255d to your computer and use it in GitHub Desktop.
Save codecademydev/76685d2b6ae00fd8fc672412c320255d to your computer and use it in GitHub Desktop.
Codecademy export
const menu = {
_courses: {
appetizers: [],
mains: [],
desserts: [],
},
get appetizers() {
return this._courses.appetizers;
},
set appetizers(appetizerIn) {
this._courses.appetizers = appetizerIn
},
get mains(){
return this._courses.mains;
},
set mains(mainIn){
this._courses.mains = mainIn
},
get desserts(){
return this._courses.desserts;
},
set desserts(dessertsIn){
this._courses.desserts = dessertIn
},
get courses() {
return {
appetizers: this.appetizers ,
mains: this.mains ,
desserts: this.desserts,
}
},
addDishToCourse(courseName, dishName, dishPrice) {
const dish = {
name: 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];
},
generateRandomMeal() {
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} and ${dessert.name}. The price is: ${totalPrice}`;
}
};
menu.addDishToCourse('appetizers', 'Spring Rolls', 2.40);
menu.addDishToCourse('appetizers', 'Vegetable Tempura', 2.00);
menu.addDishToCourse('appetizers', 'Corn Fritters', 2.10);
menu.addDishToCourse('mains', 'Tofu Green Curry', 6.50);
menu.addDishToCourse('mains', 'Mixed Vegetable Red Curry', 6.50);
menu.addDishToCourse('mains', 'Tofu Pad Thai', 6.00);
menu.addDishToCourse('desserts', 'Ice Cream', 5.00);
menu.addDishToCourse('desserts', 'Rice Pudding', 4.50);
menu.addDishToCourse('desserts', 'Hot Chocolate Fudge Cake', 6.50);
//console.log(menu._courses);
//console.log(menu._courses)
//console.log(menu.getRandomDishFromCourse(menu._courses.appetizers));
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