Skip to content

Instantly share code, notes, and snippets.

@Kharouk
Created July 2, 2018 15:33
Show Gist options
  • Save Kharouk/be871c32bef81fe85b8818d7205e742d to your computer and use it in GitHub Desktop.
Save Kharouk/be871c32bef81fe85b8818d7205e742d to your computer and use it in GitHub Desktop.
Codecademy code
const menu = {
_courses: {
appetizers: [],
mains: [],
desserts: []
},
get courses() {
return {
appetizers: this._courses.appetizers,
mains: this._courses.mains,
desserts: this._courses.desserts
}
},
get appetizers() {
},
set appetizers(appetizerIn) {
},
get mains() {
},
set mains(mainIn) {
},
get desserts() {
},
set desserts(dessertIn) {
},
addDishToCourse (courseName, dishName, dishPrice) {
const dish = {
name: dishName,
price: dishPrice
};
this._courses[courseName].push(dish);
},
getRandomDishFromCourse (courseName) {
const dishes = this._courses[courseName];
const randomNum = Math.floor(Math.random() * dishes.length);
return dishes[randomNum];
},
generateRandomMeal() {
const appetizer = this.getRandomDishFromCourse('appetizers');
const main = this.getRandomDishFromCourse('mains');
const dessert =
this.getRandomDishFromCourse('desserts');
const totalPrice = appetizer.price + main.price + dessert.price;
return `Your appetizer is ${appetizer.name}. Afterwards, we will offer you a ${main.name} for the main and we will conclude with a ${dessert.name} for your dessert. The total price will be $${totalPrice};`
}
};
menu.addDishToCourse('appetizers', 'hummus & bread', 6);
menu.addDishToCourse('appetizers', 'strawberry salad', 9);
menu.addDishToCourse('appetizers', 'cocktail sausages with homemade curry', 7);
menu.addDishToCourse('appetizers', 'cereal with smetyana', 5);
menu.addDishToCourse('appetizers', 'salmon and cream cheese', 10);
menu.addDishToCourse('appetizers', 'Caesar Salad', 4.25);
menu.addDishToCourse('mains', 'oven-grilled steak', 23);
menu.addDishToCourse('mains', 'chilli con carne with organic pork', 21);
menu.addDishToCourse('mains', 'Chicken Meatballs and Fries', 13);
menu.addDishToCourse('mains', 'Spaghetti with Lobster', 30);
menu.addDishToCourse('mains', 'Veggie Delight', 12);
menu.addDishToCourse('desserts', 'rose-tinted cheesecake', 8);
menu.addDishToCourse('desserts', 'vegan ice-cream with hash', 14);
menu.addDishToCourse('desserts', 'keto-friendly fudge brownie', 7);
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