Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created January 11, 2021 06:06
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/aef1fe20341ad2895038b2c2b398852b to your computer and use it in GitHub Desktop.
Save codecademydev/aef1fe20341ad2895038b2c2b398852b to your computer and use it in GitHub Desktop.
Codecademy export
const menu = {
_courses: {
appetizers: [],
mains: [],
desserts: [],
}, //_courses end
get appetizers (){
return this._course.appetizers;
},
get mains (){
return this._course.mains;
},
get desserts (){
return this._course.desserts;
},
set appetizers(appetizerIn){
this._courses.appetizers = appetizerIn
},
set mains(mainIn){
this._courses.mains = mainIn
},
set desserts(dessertIn){
this._courses.desserts = dessertIn
},
get courses(){
return {
appetizers: this.appetizers,
mains: this.mains,
desserts: this.desserts,
}
},//courses getter end
addDishToCourse(courseName, dishName, dishPrice) {
const dish = {
name: dishName,
price: dishPrice,
};
return this._courses[courseName].push(dish);
}, //add dish end
getRandomDishFromCourse(courseName){
const dishes = this._courses[courseName]
const randomIndex = Math.floor(Math.floor()*dishes.length);
return dishes[randomIndex];
},//end of randomdish
generateRandomMeal(){
const appetizers = this.getRandomDishFromCourse('appetizers')
const main = this.getRandomDishFromCourse('mains')
const dessert = this.getRandomDishFromCourse('desserts')
const totalPrice = appetizers.price + main.price + dessert.price;
return `You should try this meal ${appetizers.name}, ${main.name}, ${dessert.name}. It only costs: ${totalPrice}`;
}
}; //menu end
menu.addDishToCourse('appetizers', 'breadsticks', 6.50);
menu.addDishToCourse('appetizers', 'salad', 4.00)
menu.addDishToCourse('appetizers', 'cheese sticks', 9.00)
menu.addDishToCourse('mains', 'steak', 18.00)
menu.addDishToCourse('mains', 'chicken', 12.00)
menu.addDishToCourse('mains', 'fish', 16.00)
menu.addDishToCourse('desserts', 'cheescake', 11.00)
menu.addDishToCourse('desserts', 'ice cream', 1.00)
menu.addDishToCourse('desserts', 'brownie', 9.00)
let meal = menu.generateRandomMeal()
console.log(meal)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment