-
-
Save simonblakemore/1e916a5e73dea1bb172f33a973fc4f43 to your computer and use it in GitHub Desktop.
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); |
Thanks! It was a very frustrating code academy project... I dont understand the reason wich codeacademy has not published the solution for this project... :(
Thank you !
شكر! كان مشروع أكاديمي رمز محبط للغاية ... أنا لا أفهم السبب الذي لم ينشر codeacademy الحل لهذا المشروع ... :(
You're welcome. I'm happy it helped
I was nowhere near the finish line here. This Codecademy project took me through the step by step minutae without me really understanding the point of the intermediary steps I was taking. Thanks for posting.
Yes. I subscribed to the PRO version because of the projects and came across this one.
Extremely bad. Nothing makes sense as you go along. That's no way to teach anything. You only get good at typing without understanding anything. I really hope the next ones are better as this was very very disappointing from Codecademy.
Thank you, i was struggling with this one!
glad to know I am not the only one struggling with this one =) thank you.
Thank you. I was about to give up on this one. You saved the day.
Codecademy teach on piano: This is a C,E,D,G,H,C.. okey good.. now lets play some Prelude from Johann Sebastian Bach..
can somehow explain the project because I don't really understand it, I was just following up
Oh man. I am so glad to see others struggled with this one too. It made no sense to me and the steps were HORRIBLE written. Thanks for posting this.
Thank you
at some point, the error "Cannot read property 'push' of undefined" occurred and it is not clear why
Thanks!
I was struggling for this one for a long time
Thanks, simonblakemore.
I too was getting "cannot read property 'push' of undefined" error. And couldn't get past it after spending too much time on this. As a last attempt, reset the project to start again and closely follow the instructions, only to run into the same error message again. Comparing my code to yours, I could see a couple of differences, but not to a degree where it woul be a factor (a semi colon here and there, a coma, and this line: this._courses[courseName].push(dish); I had as this._courses.[courseName].push(dish) -period before the opening bracket.
This project was more challenging than I expected
Even after reading the code solution, it's hard to understand the meaning of all steps, i wish they could they had explain it a bit more...
And why not to use classes object here ?
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.
Thank you!!!
This particular project on code academy was terrible. Lol.
Thanks for this, was struggling with this one!