Help please for Meal Maker

Can someone please tell me why I cannot get this project to run properly? I have been stuck with the same error message below and have the identical code to the instructions. I do not understand why this isnt working.

getRandomDishFromCourse(courseName){
    const dishes = menu._courses[courseName];
    const numberIndex = Math.floor(Math.random() * dishes.length);
    return dishes[numberIndex];
  },
ERRROR MESSAGE: /home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:45
    const numberIndex = Math.floor(Math.random() * dishes.length);
                                                    ^

TypeError: Cannot read property 'length' of undefined

difficult to say without seeing the rest of your code, you could start by logging the variable involved:

console.log(menu, menu._courses, courseName, menu._courses[courseName])
const dishes = menu._courses[courseName];

see what results in the undefined, and then work your way through the code

1 Like

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