-
-
Save codecademydev/29390b6ceca1800d362531650e095f0b 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; | |
}, | |
set appetizers(appetizerIn){ | |
return this._courses.appetizers = appetizersIn; | |
}, | |
get mains () { | |
return this._courses.mains; | |
}, | |
set mains (mainIn) { | |
return this._courses.mains = mainsIn; | |
}, | |
get desserts (){ | |
return this._courses.desserts; | |
}, | |
set desserts (dessertIn){ | |
return this._courses.desserts = dessertIn; | |
}, | |
get courses () { | |
return { | |
appetizers:this.appetizers, | |
mains:this.mains, | |
desserts:this.desserts | |
} | |
}, | |
addDishToCourse (courseName, dishName, dishPrice) { | |
this._courses[courseName].push( { dishName, dishPrice } ); | |
}, | |
getRandomDishFromCourse (courseName) { | |
let dishes = this._courses[courseName]; | |
let randomDish = Math.floor(Math.random() * dishes.length); | |
return dishes[randomDish]; | |
}, | |
generateRandomMeal () { | |
const appetizer = this.getRandomDishFromCourse('appetizers'); | |
const main = this.getRandomDishFromCourse('mains'); | |
const dessert = this.getRandomDishFromCourse('desserts'); | |
// console.log(this.appetizers); | |
const totalPrice = this.appetizer.dishPrice + this.mains.dishPrice + this.desserts.dishPrice; | |
console.log(this.appetizer.dishPrice, this.mains.dishPrice, this.desserts.dishPrice); | |
return `The cost your meal is ${totalPrice}. It includes ${this.appetizers.name}, ${this.mains.dishName} and finishes with ${this.desserts.dishName}.` | |
} | |
}; | |
menu.addDishToCourse('appetizers', 'Burrata & Peppers', 5.95); | |
menu.addDishToCourse('appetizers', 'Calamari', 6.5); | |
menu.addDishToCourse('appetizers', 'Steak Tartare', 11); | |
menu.addDishToCourse('mains', 'Spaghetti a la vongle', 13.95); | |
menu.addDishToCourse('mains', 'Steak & Stilton Pie', 11.95); | |
menu.addDishToCourse('mains', 'Beef Pho', 12.95); | |
menu.addDishToCourse('desserts', 'New York Cheesecake', 7.95); | |
menu.addDishToCourse('desserts', 'Croqueembouche', 14.95); | |
menu.addDishToCourse('desserts', 'Knickerbocker Glory', 6.50); | |
//console.log(menu._courses); | |
console.log(menu.generateRandomMeal()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment