-
-
Save codecademydev/5a73475bfdfff2941ab427ee04b9851d 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
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._courses.appetizers, | |
mains: this._courses.mains, | |
desserts: this._courses.desserts, | |
} | |
}, | |
addDishToCourse(courseName, dishName, dishPrice) { | |
const dish = { | |
name: dishName, | |
price: dishPrice, | |
} | |
this._courses[courseName].push(dish); | |
}, | |
getRandomDishFromCourse(courseName) { | |
const dishes = this._courses[courseName]; | |
let random = Math.floor(Math.random() * dishes.length); | |
return dishes[random]; | |
}, | |
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 `You ordered: ${appetizer.name}, ${main.name}, and ${dessert.name}. Your total price is \$${totalPrice}`; | |
} | |
} | |
menu.addDishToCourse('desserts', 'lemon curd tart', 8.74); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment