Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created December 8, 2021 21:36
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/8ae946d0fe4d8263cc57f671bcd4bc03 to your computer and use it in GitHub Desktop.
Save codecademydev/8ae946d0fe4d8263cc57f671bcd4bc03 to your computer and use it in GitHub Desktop.
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) {
this._courses.appetizers = appetizers;
},
set mains(mains) {
this._courses.mains = mains;
},
set desserts(desserts) {
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._courses[courseName];
const randomIndex = Math.floor(Math.random() * dishes.length);
return dishes[randomIndex];
},
generateRandomMeals() {
const appetizers = this.getRandomDishFromCourse('appetizers')
const mains = this.getRandomDishFromCourse('main')
const desserts = this.getRandomDishFromCourse('desserts')
const totalPrice = appetizer.price + mains.price + desserts.price
return `Your meal is ${appetizer.name}, ${mains.name}, ${desserts.name} and your total price is $${totalPrice}.`;
}
};
menu.addDishToCourse('appetizers', 'wings', 5.34);
menu.addDishToCourse('appetizers', 'nachos', 6.00);
menu.addDishToCourse('appetizers', 'poutine', 7.00);
menu.addDishToCourse('main', 'pasta', 10.00);
menu.addDishToCourse('main', 'steak', 11.00);
menu.addDishToCourse('main', 'pizza', 12.00);
menu.addDishToCourse('desserts', 'cake', 5.00);
menu.addDishToCourse('desserts', 'ice cream', 7.00);
menu.addDishToCourse('desserts', 'fruit', 4.00);
let meal = menu.generateRandomMeals();
console.log(meal);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment