Meal Maker project

Hello everyone, I keep getting this error message and I just don’t know what to do about it. Any help?
/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:7
return this._courses.appetizers;
^

TypeError: Cannot read property ‘appetizers’ of undefined
at Object.get appetizers [as appetizers] (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:7:26)
at Object.addDishToCourse (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:37:25)
at Object. (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:56:6)
at Module._compile (module.js:571:32)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)

Hello @sam_damilola! Welcome to the Community!

If you go through the error message, it says that the property appetizers is undefined which means that JavaScript wasn’t able to find the appetizers property. What do you think could be the reason behind that? Ask yourself these questions: Is the property defined? If the property is defined, is it defined in the correct place?

I believe if you can answer these, you’ll find the answer to your problem. So, what do you think?

1 Like

Thank you for your reply. I really appreciate it. I understand that it’s initially set to an empty array, but that array gets to have elements down the code. In the addDishToCourse() function.

That’s my thought.

1 Like

if you look at the error message:

at Object.get appetizers [as appetizers] (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:7:26)

you can see the line number (7), which is this line:

       return this._courses.appetizers;

of your appetizers getter

so this._courses gives undefined, and undefined does not have a appetizers property

1 Like

Oh wow!!!
I see it now!! My getter and setter should be after the courses object not within it!!!

Code runs perfectly now!!
Thanks a lot for your time!!

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.