this issue has come up so many times on the forum, the problem is that here:
this._courses[courseName]
you use a key which doesn’t exists on courses object
which result in undefined (In my opinion JS should throw an error here). given .push() is a array method, and you try to call this method on undefined, you get an error
you should find out which key you attempt to use that doesn’t exists, you could start by logging (console.log(courseName)) to narrow the problem down
Do you feel like you have a good grasp on what the addDishToCourse method is supposed to do? Could you describe it to another person? If not, which parts don’t make sense?
The addDishToCourse is to take 2 parameters as strings and dishPrice wish is a number the dish object inside addDishToCourse is to receive the string of dishName and number of dishPrice to value of it’s keys, save it under one variable and push this._courses[coursesName] to “dish”.
I tried to add new property to menu._courses with key of coursesName and with empty array as its value to see if it’s giving error because it can’t find coursesName but error is this “Cannot read property ‘push’ of undefined
at Object.addDishToCourse”