-
-
Save codecademydev/23720958c6f31fbab94bbe47c4577615 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 | |
}, | |
get mains() { | |
return this._courses.mains | |
}, | |
get desserts() { | |
return this._courses.desserts | |
}, | |
set appetizers(appetizersIn){ | |
this._courses.appetizers | |
}, | |
set mains(mainsIn) { | |
this._courses.mains | |
}, | |
set desserts(dessertsIn) { | |
this._courses.desserts | |
}, | |
get courses() { | |
return { | |
appetizers: this.appetizers, | |
mains: this.mains, | |
desserts: this.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: function (courseName) { | |
const dishes = this._courses[courseName]; | |
const randomIndex = Math.floor(Math.random() * dishes.length); | |
return dishes[randomIndex]; | |
}, | |
generateRandomMeal: function () { | |
const appetizer = this.getRandomDishFromCourse('appetizer'); | |
const main = this.getRandomDishFromCourse('main'); | |
const desserts = this.getRandomDishFromCourse('dessert'); | |
const totalPrice = appetizer.price + main.price + dessert.price | |
return `Your meal is ${appetizer.name}, ${main.name}, ${desserts.name} The price is ${totalPrice}.`; | |
} | |
} | |
menu.addDishToCourse('Steak', 'Salad', 5); | |
const meal = menu.generateRandomMeal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment