Skip to content

Instantly share code, notes, and snippets.

@simonblakemore
Created October 16, 2017 11:37
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save simonblakemore/1e916a5e73dea1bb172f33a973fc4f43 to your computer and use it in GitHub Desktop.
Save simonblakemore/1e916a5e73dea1bb172f33a973fc4f43 to your computer and use it in GitHub Desktop.
Codecademy: Meal Maker Lesson - Day 15
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);
@unixthat
Copy link

Thanks for this, was struggling with this one!

@urco
Copy link

urco commented Dec 18, 2018

Thanks! It was a very frustrating code academy project... I dont understand the reason wich codeacademy has not published the solution for this project... :(

@kevintravels93
Copy link

Thank you !

@mustafaalawad
Copy link

شكر! كان مشروع أكاديمي رمز محبط للغاية ... أنا لا أفهم السبب الذي لم ينشر codeacademy الحل لهذا المشروع ... :(

@simonblakemore
Copy link
Author

You're welcome. I'm happy it helped

@skeet-skeet
Copy link

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.

@GuillermoJus
Copy link

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.

@fadjriaf
Copy link

Thank you, i was struggling with this one!

@maksgal
Copy link

maksgal commented Feb 18, 2020

glad to know I am not the only one struggling with this one =) thank you.

@vienvo
Copy link

vienvo commented Mar 17, 2020

Thank you. I was about to give up on this one. You saved the day.

@stefancoding7
Copy link

Codecademy teach on piano: This is a C,E,D,G,H,C.. okey good.. now lets play some Prelude from Johann Sebastian Bach..

@phantware
Copy link

can somehow explain the project because I don't really understand it, I was just following up

@Chknbone
Copy link

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.

@ArtemBYN
Copy link

ArtemBYN commented Jun 7, 2020

Thank you
at some point, the error "Cannot read property 'push' of undefined" occurred and it is not clear why

@rrabi10
Copy link

rrabi10 commented Sep 3, 2020

Thanks!
I was struggling for this one for a long time

@Serg911
Copy link

Serg911 commented Oct 3, 2020

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

@Gregprod33
Copy link

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 ?

@noni007
Copy link

noni007 commented Nov 26, 2020

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.

Copy link

ghost commented Mar 6, 2021

Thank you!!!

@smyja
Copy link

smyja commented Dec 26, 2021

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