Javascript Project Meal Maker

I keep getting an error not sure why?
Any ideas guys ? thanks!

1 Like

You have to look at the error itself. When I run your code it reads

return this._courses[courseName].push(dish);
                                                             
TypeError: Cannot read property 'push' of undefined

That should be a good clue. Consider, what value is this._courses[courseName] giving you? Try console.log on that value before the return line to get a better idea.

2 Likes

Thanks for responding. It says undefined when I console.log(this._courses[courseName]), so I reckon something is wrong in that its not recognising the this._courses[courseName] as being equal to the arrays underneath _courses.

Still can’t figure it out though :frowning:

Took a look at the code. The .push() error for undefined is because… well, nothing is defined! Pay attention to typos.
You have:

let menu = {
 _courses: {
   appetizers: [],
   mains: [],
   desserts: []
   },

but when you add dishes you have:

menu.addDishToCourse('appetizer', 'Cutlets', 0.3);
menu.addDishToCourse('main', 'Biryani', 4);

Did you spot the difference?

2 Likes

this._courses.appetizers throws this TypeError: Cannot read property 'appetizers' of undefined

So it’s helpful to go down the rabbit hole of checking that all your parameters are logging as you want them to be logging. It may seem tedious, but it’s a common process that’ll make you stronger as a programmer.

1 Like

This is embarrassing…thanks so much man! I made a few mistakes and this was probably the biggest one. Thanks!

1 Like

Thanks so much once again bro, you are correct I did what you said and finally found the error!

Since the program does not use the getters or setters we don’t see the circular reference error.