Created
October 16, 2017 11:37
-
-
Save simonblakemore/1e916a5e73dea1bb172f33a973fc4f43 to your computer and use it in GitHub Desktop.
Codecademy: Meal Maker Lesson - Day 15
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._appetizers; | |
}, | |
set appetizers(appetizersIn) { | |
this._appetizers = appetizersIn; | |
}, | |
get mains() { | |
return this._mains; | |
}, | |
set mains(mainsIn) { | |
this._mains = mainsIn; | |
}, | |
get desserts() { | |
return this._desserts; | |
}, | |
set desserts(dessertsIn) { | |
this._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); | |
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} and ${dessert.name}. The price is $${totalPrice.toFixed(2)}.`; | |
}, | |
}; | |
menu.addDishToCourse('appetizers', 'Ceasar Salad', 4.25); | |
menu.addDishToCourse('appetizers', 'Prawn Coctail', 4.25); | |
menu.addDishToCourse('appetizers', 'Garlic Bread', 3.50); | |
menu.addDishToCourse('mains', 'Lasagna', 9.75); | |
menu.addDishToCourse('mains', 'Ribeye Steak', 14.95); | |
menu.addDishToCourse('mains', 'Fish & Chips', 12.95); | |
menu.addDishToCourse('desserts', 'Cheese Cake', 4.50); | |
menu.addDishToCourse('desserts', 'Creme Brule', 4.25); | |
menu.addDishToCourse('desserts', 'Cheese Board', 3.25); | |
let meal = menu.generateRandomMeal(); | |
console.log(meal); |
Thank you!!!
This particular project on code academy was terrible. Lol.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was so crazy. Imagine taking your time, referring to previous object lessons before the project to make sure you did not miss something. At some point I had to ask myself if I had tried all I could. Went on the forum as well and still could not understand why the"push method on dishes" was throwing a flag. Just glad to know I was not running crazy when I saw the comments here @simonblackmore thanks for this.