-
-
Save codecademydev/469d2428f354af3de9e6f48ba2859357 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() { | |
this._courses.appetizers; | |
}, | |
get mains() { | |
this._courses.mains; | |
}, | |
get desserts() { | |
this._courses.desserts; | |
}, | |
set appetizers(appetizers) { | |
this._courses.appetizers = appetizers; | |
}, | |
set mains(mains) { | |
this._courses.mains = mains; | |
}, | |
set desserts(desserts) { | |
this._courses.desserts = desserts; | |
}, | |
get courses() { | |
return { | |
appetizers: this.appetizers, | |
mains: this.mains, | |
desserts: this.desserts, | |
}; | |
}, | |
addDishToCourse(courseName, dishName, dishPrice) { | |
const dish = { | |
name: dishName, | |
price: dishPrice | |
}; | |
return this._courses[courseName].push(dish); | |
}, | |
getRandomDishFromCourse(){ | |
const dishes = this._courses[courseName]; | |
const randomIndex = Math.floor(Math.random() * dishes.length); | |
return dishes[randomIndex]; | |
}, | |
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 meal is ${appetizer.name}, ${main.name}, ${dessert.name} and your total prize equals ${totalPrice} `; | |
} | |
}; | |
menu.addDishToCourse('appetizers', 'salad', 9.99); | |
menu.addDishToCourse('appetizers', 'Garlic mushrooms', 7.99); | |
menu.addDishToCourse('appetizers', 'Fries', 9.99); | |
menu.addDishToCourse('Mains', 'fish', 19.99); | |
menu.addDishToCourse('Mains', 'Steak', 7.99); | |
menu.addDishToCourse('Mains', 'Veggie Burger', 9.99); | |
menu.addDishToCourse('desserts', 'cake', 9.99); | |
menu.addDishToCourse('desserts', 'Ice cream', 7.99); | |
menu.addDishToCourse('desserts', 'Coffee', 3.99); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment