-
-
Save codecademydev/956772af8e3796696041342dc19a7d71 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) { | |
this._courses.appetizers = appetizerIn | |
}, | |
get mains() { | |
return this._courses.mains; | |
}, | |
set mains(mainIn) { | |
this._courses.mains = mainIn | |
}, | |
get desserts() { | |
return this._courses.desserts; | |
}, | |
set desserts(dessertIn) { | |
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 | |
}; | |
return 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); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment