JS Syntax II Objects project <Meal Maker>

I am stuck…

Please help me out :’(
And, I don’t think the ‘addDishToCourse’ method is recognized as a method, because the color of parameters is still red.
I’ve been stuck for so long I’m starting to get a headache…

Also, what are the roles of ‘getter’ and ‘setter’ in this? And why are they both needed?

Hey!

You’re adding food to wrong arrays!
The name of your arrays are ‘appetizers’, ‘mains’ and ‘desserts’. However, if you look at the calls to the addDishToCourse() method, you’re adding to other arrays.


menu.addDishToCourse('appetizers', 'House Salad', 3.00);
menu.addDishToCourse('appetizers', 'Potato Soup', 2.00);
menu.addDishToCourse('appetizers', 'BBQ Wings', 4.00);

menu.addDishToCourse('main', 'Steak', 15.00);
menu.addDishToCourse('main', 'Seafood Pasta', 18.00);
menu.addDishToCourse('main', 'Vegie Pizza', 12.00);

menu.addDishToCourse('dessert', 'Icecream', 6.00);
menu.addDishToCourse('dessert', 'Chocolate Muffin', 4.00);
menu.addDishToCourse('dessert', 'Churros', 2.00);

You’re adding to ‘main’ instead of mains and ‘dessert’ instead of desserts. Fix that to the following:

menu.addDishToCourse('appetizers', 'House Salad', 3.00);
menu.addDishToCourse('appetizers', 'Potato Soup', 2.00);
menu.addDishToCourse('appetizers', 'BBQ Wings', 4.00);

menu.addDishToCourse('mains', 'Steak', 15.00);
menu.addDishToCourse('mains', 'Seafood Pasta', 18.00);
menu.addDishToCourse('mains', 'Vegie Pizza', 12.00);

menu.addDishToCourse('desserts', 'Icecream', 6.00);
menu.addDishToCourse('desserts', 'Chocolate Muffin', 4.00);
menu.addDishToCourse('desserts', 'Churros', 2.00);

Your problem should be fixed then.

Also, to clear your question about the roles of getter and setter methods in this code and why they’re needed, refer below:

I think in this particular case, it is more of a training exercise to make you more familiarized with the concepts of getters and setters but if you even remove them from your code, your code should work just fine. And, as the lesson says, it’s a good idea to access properties of an object using getters and setters and you should practice them.

Thank you so much! :smiley:

I tried the edited version, but I get this kind of result:

Today’s meal: [object Object], [object Object], and [object Object]. The total price is: 26.

How can I fix [object Object] to names of dishes? :confused:

the line you talk about is here:

return `Today's meal: ${appetizer}, ${main}, and ${dessert}. The total price is: ${totalPrice}.`

we can see you try to use the objects, which property of the object do we want here?

You’re returning the entire object in the return string instead of the name property of the object.

Instead of doing this,

return `Today's meal: ${appetizer}, ${main}, and ${dessert}. The total price is: ${totalPrice}.`

Try:

return `Today's meal: ${appetizer.name}, ${main.name}, and ${dessert.name}. The total price is: ${totalPrice}.`

This should print the name of the dish for you!