Meal maker - getters and setters

Im also having trouble. My code is https://gist.github.com/0488b5688fed849bddc2488f2e47de70
I am getting this error
this._courses[courseName].push(this.dish);
^

TypeError: Cannot read property ‘push’ of undefined
at Object.addDishToCourse (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:40:31)
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)
at startup (bootstrap_node.js:151:9)

Your problem is here:

const menu = {
  _courses: {
    appetizers: [],
    mains: [],
    desserts: [],
  get appetizers() {
     return this._appetizers;
   }
  },
  get appetizers() {
    return this._courses.appetizers;
  },

You have accidentally included a get appetizers() method inside of _courses which is clashing with your appetizers property and throwing an error. Remove this and you should get past that error.

I fixed that,but im still getting the erorr.

On lines 61-63 you have called addDishToCourse() with ‘deserts’ but it should be ‘desserts’, which fixes that issue! I believe there’s another couple errors in the code you shall encounter after these, give them a go first yourself and then ask if you need any more help.

1 Like