Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created July 17, 2019 02:52
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/5809589b3bff0eb42c77ee43a2ac6bd8 to your computer and use it in GitHub Desktop.
Save codecademydev/5809589b3bff0eb42c77ee43a2ac6bd8 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(appetizers){
this._courses.appetizers = appetizers;
},
get mains() {
return this._courses.mains;
},
set mains(mains) {
this._courses.mains = mains;
},
get desserts() {
return this._courses.desserts;
},
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
};
//Error message here
return this._courses[courseName].push(dish);
},
getRandomDishFromCourse(courseName) {
const dishes = this._courses[courseName];
const randomDish = Math.floor(Math.random() * dishes.length);
return dishes[randomDish];
},
generateRandomMeal() {
const appetizer = this.getRandomDishFormCourse('appetizers');
const main = this.getRandomDishFromCourse('mains');
const dessert = this.getRandomdishCourse('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('appetizer', 'wings', 5);
menu.addDishToCourse('appetizer', 'soup', 6);
menu.addDishToCourse('appetizer', 'salad', 2);
menu.addDishToCourse('main', 'sushi', 7);
menu.addDishToCourse('main', 'salmon', 10);
menu.addDishToCourse('main', 'burger', 9);
menu.addDishToCourse('dessert', 'cake', 8);
menu.addDishToCourse('dessert', 'ice cream', 5);
menu.addDishToCourse('dessert', 'cookies', 4);
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