-
-
Save codecademydev/87f14462daa8b6055aa27a617cd3e0c5 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(){ | |
}, | |
get mains(){ | |
}, | |
get desserts (){ | |
}, | |
set appetizers(appetizersIn){ | |
}, | |
set mains(mainsIn){ | |
}, | |
set desserts(dessertsIn){ | |
}, | |
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]; | |
const randomIndex = | |
Math.floor(Math.random() * dishes.length); | |
}, | |
generateRandomMeal: function () { | |
const appetizers = this.getRandomDishFromCourse('appetizers'); | |
const main = this.getRandomDishFromCourse('main'); | |
const disserts = this.getRandomDishFromCourse('disserts'); | |
const totalPrice = appetizers.price + main.price + disserts.price; | |
return `Your meal is ${appetizers.name}, ${main.name}, ${disserts.name} and The price is ${totalPrice}.`; | |
}, | |
}; | |
menu.addDishToCourse('appetizers', 'Caesar Salad', 4.25); | |
menu.addDishToCourse('main', 'Caesar Salad', 4.25); | |
menu.addDishToCourse('desserts', 'Caesar Salad', 4.25); | |
let meal = menu.generateRandomMeal(); | |
console.log(meal); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment