Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created April 14, 2020 18:35
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/4885dae9cf15b44dd0cf20149b2eae94 to your computer and use it in GitHub Desktop.
Save codecademydev/4885dae9cf15b44dd0cf20149b2eae94 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 = appeizerIn;
},
get mains () {
return this._courses.mains
},
set mains(mainsIn){
this._courses.mains = mainsIn;
},
get desserts (){
return this._courses.desserts;
} ,
set desserts (dessertsIn){
this._courses.desserts = desserts;
},
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._course[courseName]
const randomIndex = Math.floor(Math.random () * dishes.length )
return dishes[randomIndex];
},
generateRendomMeal(){
const appetizer = this.getRandomDishFromCourse('appetizers');
const main = this.getRandomDishFromCourse('mains');
const dessert = this.getRandomDishFromCourse('desserts');
const totalPrice = apetizer.price + main.price + dessert.price;
return `Your meal is ${appetizer.name}, ${main.name}, and ${dessert.name}, and the total price is ${totalPrice}.`
}
};
menu.addDishToCourse('appetizer', 'salad', 4.00)
menu.addDishToCourse('appetizer', 'wings', 4.50)
menu.addDishToCourse('appetizer', 'fries', 5.00)
menu.addDishToCourse('main', 'steak', 10.00)
menu.addDishToCourse('main', 'salmon', 7.75)
menu.addDishToCourse('main', 'tofu', 11.20)
menu.addDishToCourse('dessert', 'ice cream', 3.00)
menu.addDishToCourse('dessert', 'coffee', 3.00)
menu.addDishToCourse('dessert', 'cakw', 3.25)
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