Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created March 10, 2021 17:28
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/75325732448d51a8a986ef90ac827034 to your computer and use it in GitHub Desktop.
Save codecademydev/75325732448d51a8a986ef90ac827034 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,
};
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 desert = this.getRandomDishFromCourse('deserts');
const totalPrice = appetizer.price + main.price + dessert.price;
return `Your meal is ${appetizer.name}, ${main.name}, and ${dessert.name} and the total prics is ${totalPrice}`;
}
};
menu.addDishToCourse('appetizers', 'salad', 4.00);
menu.addDishToCourse('appetizers', 'wings', 4.50);
menu.addDishToCourse('appetizers', 'fries', 5.00);
menu.addDishToCourse('mains', 'steak', 10.25);
menu.addDishToCourse('mains', 'salmon', 7.75);
menu.addDishToCourse('mains', 'tofu', 11.00);
menu.addDishToCourse('deserts', 'ice cream', 3.00);
menu.addDishToCourse('deserts', 'coffee', 3.00);
menu.addDishToCourse('deserts', 'cake', 3.25);
const mdeal = menu.generateRandomMeal();
console.log(meal);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment