-
-
Save codecademydev/e126ed1f4c32c9bfd49dc6f589de1e83 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let menu = { | |
_courses: { | |
appetizers: [], | |
mains: [], | |
desserts: [] | |
}, | |
get appetizers() { | |
return this._courses.appetizers; | |
}, | |
set appetizers(appetizerIn) { | |
return this._courses.appetizers = appetizerIn | |
}, | |
get mains() { | |
return this._courses.mains; | |
}, | |
set mains(mainIn) { | |
return this._courses.mains = mainIn | |
}, | |
get desserts() { | |
return this._courses.desserts; | |
}, | |
set desserts(dessertIn) { | |
return this._courses.desserts = dessertIn | |
}, | |
get _courses() { | |
return { | |
appetizers: this.appetizers, | |
mains: this.mains, | |
desserts: this.desserts, | |
} | |
}, | |
addDishToCourse (courseName, dishName, dishPrice) { | |
const dish = { | |
name: this.courseName, | |
price: this.dishPrice | |
}; | |
this._courses[courseName].push(dish); | |
}, | |
getRandomDishFromCourse(courseName) { | |
let dishes = this._courses[courseName]; | |
const randomIndex = Math.floor(Math.random() * dishes.length); | |
return dishes[randomIndex] | |
}, | |
generateRandomMeal: function() { | |
const appetizer = this.getRandomDishFromCourse('appetizers'); | |
const main = this.getRandomDishFromCourse('mains'); | |
const dessert = this.getRandomDishFromCourse('desserts'); | |
const totalPrice = appetizer.price + main.price + dessert.price; | |
return `You have ordered ${appetizer.name}, ${main.name} and ${dessert.name}. The total price is ${totalPrice}`; | |
} | |
}; | |
menu.addDishToCourse('dessert', 'chocolate pie', 1.75); | |
menu.addDishToCourse('dessert', 'fruit plate', 7.50); | |
menu.addDishToCourse('dessert', 'galette des rois', 10.85); | |
menu.addDishToCourse('main', 'pizza', 6.75); | |
menu.addDishToCourse('main', 'pasta with tuna', 4.55); | |
menu.addDishToCourse('main', 'hamburger', 2.75); | |
menu.addDishToCourse('appetizer', 'salad with tuna', 4.45); | |
menu.addDishToCourse('appetizer', 'mayo with eggs', 1.25); | |
menu.addDishToCourse('appetizer', 'bread with cheese', 14.45); | |
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