Please help with The Meal Maker project

can anyone help me with this …
i got a error in the end of the project , i check the functions and i cant really find the problem but this the everything is coming undefined.
“Your meal is undefined, undefined, undefined, The price is $NaN.”
here is my code

you could work back-wards, so lets see what getRandomDishFromCourse returns for appetizer for example:

  generateRandomMeal(){
    const appetizers = this.getRandomDishFromCourse("appetizers");
    console.log(appetizers);
    const mains = this.getRandomDishFromCourse("mains");
    const desserts = this.getRandomDishFromCourse("desserts");
    const totalPrice = appetizers.price + mains.price + desserts.price;
    return `Your meal is ${appetizers.name}, ${mains.name}, ${desserts.name}, The price is $${totalPrice}.`;
  }

see how I inserted a .log()? Now we can see what getRandomDishFromCourse returns

so an object is returned, as expected, but the properties are different from the ones you attempt to use.

This leaves you with two options:

  1. change the properties when calculating total price and returning the string
  2. change the properties of dish object in addDishToCourse method.

Lets see so basically you saying i need to do this :
generateRandomMeal(){

const appetizers = this.getRandomDishFromCourse("appetizers");

const mains = this.getRandomDishFromCourse("mains");

const desserts = this.getRandomDishFromCourse("desserts");

const totalPrice = appetizers.dishPrice + mains.dishPrice + desserts.dishPrice;

return `Your meal is ${appetizers.dishName}, ${mains.dishName}, ${desserts.dishName}, The price is $${totalPrice}.`;

that is option 1, option 2 would be change the object itself:

  addDishToCourse (courseName,dishName,dishPrice) {
    // could change the properties of dish object, if you want to use `.price` later
    const dish = {
      courseName,
      dishName,
      dishPrice,
    };

either change is fine. That is up to you. Just ensure that the right properties are used at both places

1 Like

Fantastic, Thank you very Much…

You’re welcome :slight_smile:

I don’t feel like telling you exactly what property names you should use, I assume you are perfectly capable of deciding that for yourself :wink: you can decide what names you find more pleasant.

I am more focusing you understand what is happening and where you went wrong, which you seem to understand really well now :slight_smile: good job :slight_smile:

1 Like

To be honest i not really getting what should i do in the second option that you gave me, im a bit confused what i should do…

with the addDishToCourse method we add on object to a course array (mains for example)

then getRandomDishFromCourse gets a random object from a course array.

if we want to use .price as property on this object, we would need to declare the property as such when we create the object:

 const dish = {
      courseName,
      dishName,
      price: dishPrice,
    };

now we can use .price instead of .dishPrice.

1 Like

ohh ok, makes sense, i understand now, thanks for your help :smiley:

1 Like