Meal Maker - NaN & Undefined

Hi all,

First post to the forums so be easy on me. I’m working my way through the Meal Maker project and am having a few issues - it started with .push() returning undefined but I’ve managed to fix that thanks to some posts on here :slight_smile:

My issue with my code now is that my generateRandomMeal() method is returning NaN for the price and undefined for my dishNames. My code is below:

From what I can gather with the error messages I have had with toying with my code - I need to access the dishName & dishPrice properties in the arrays for my courses but I’m not sure how to access these.

Any help would be great as I feel like I’m banging my head against a wall at the moment :slightly_frowning_face:

Hello, and welcome to the forums!

After these lines in your code, you have access to everything you need

    const appetizer = this.getRandomDishFromCourse('appetizers');
    const main = this.getRandomDishFromCourse('mains');
    const dessert = this.getRandomDishFromCourse('desserts');

They will each be an object that has the price and name. Try logging one of those variables before the rest of your code. You’ll be able to see what you’re working with and then adjust the rest of the code in that function.

Click for an extra hint

Each variable will be assigned a random object from the arrays. So you will have access to main.dishName and main.dishPrice, for example.

1 Like

Thanks so much for your help!

Turns out I was over thinking what I was trying to access & where - a fresh pair of eyes was what I needed :grinning:

1 Like