-
-
Save codecademydev/3987fee3f70953ff618d701ba48d75b8 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: { | |
appitizers: [], | |
mains: [], | |
desserts: [] | |
}, | |
get appitizers() { | |
return this._courses.appitizers; | |
}, | |
get mains() { | |
return this._courses.mains; | |
}, | |
get desserts() { | |
return this._courses.desserts; | |
}, | |
set appitizers(appitizerIn){ | |
this._courses.appitizers = appitizerIn; | |
}, | |
set mains(mainIn){ | |
this._courses.mains = mainIn; | |
}, | |
set desserts(dessertIn){ | |
this._courses.desserts = dessertIn; | |
}, | |
get courses() { | |
return { | |
appitizers: this.appitizers, | |
mains: this.mains, | |
desserts: this.desserts, | |
}; | |
}, | |
addDishToCourse(courseName, dishName, dishPrice) { | |
const dish = { | |
name: dishName, | |
price: dishPrice | |
}; | |
this._courses[courseName].push(dish); | |
}, | |
getRandomDishFromCourse(courseName) { | |
const dishes = this._courses[courseName]; | |
const randomIndex = Math.floor(Math.random() * dishes.length); | |
return dishes[randomIndex]; | |
}, | |
generateRandomMeal: function() { | |
const appitizer = this.getRandomDishFromCourse('appitizers'); | |
const main = this.getRandomDishFromCourse('mains'); | |
const dessert = this.getRandomDishFromCourse('desserts'); | |
const totalPrice = appitizer.price + main.price + dessert.price; | |
return `Your mean includes: ${appitizer}, ${main} and ${dessert}. Total Cost: ${totalPrice}` | |
} | |
}; | |
menu.addDishToCourse('appitizers', 'Cheesy', 1.50); | |
menu.addDishToCourse('appitizers', 'Garlic', 3); | |
menu.addDishToCourse('appitizers', 'Eggs', 4.50); | |
menu.addDishToCourse('mains', 'Rump', 8.50); | |
menu.addDishToCourse('mains', 'Alfredo', 7); | |
menu.addDishToCourse('mains', 'Vegan', 10); | |
menu.addDishToCourse('desserts', 'Nuetlla', 5); | |
menu.addDishToCourse('desserts', 'Cremé', 6.50); | |
menu.addDishToCourse('desserts', 'Sorbet', 4.50); | |
const meal = menu.generateRandomMeal(); | |
console.log(meal); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment