Meal Maker - Output Error (Javascript)

Good day,

I seem to be experiencing an output error with my code on the below Project: Meal Maker. I cannot seem to find what is causing this output.

Your mean includes: [object Object], [object Object] and [object Object]. Total Cost: 19.5

My Code:

You’re accessing the price property of the objects in order to calculate the Total Cost, which is working. However, when you’re trying to print the name of the dish, you’re using the whole object instead of the name property

Ah! Got it! Thanks, it’s sorted.

I misunderstood this:
const appitizer = this.getRandomDishFromCourse(‘appitizers’);

So the appitizers array is storing both the name of the dish and the price under one Index, both of which are being selected and stored in the appitizer const under generateRandomMeal, correct?

Yes, your arrays in _courses are storing whatever you push to them, and your method here is what is doing it:

  addDishToCourse(courseName, dishName, dishPrice) {
    const dish = {
        name: dishName,
        price: dishPrice

So since you are creating an object with name and price properties and then pushing the object to the array, the full object is returned when you use this.getRandomDishFromCourse('appitizers').

If you had added other properties to the object in your addDishToCourse() method, then they would also be available when you retrieve the object from the array.

1 Like

Got it!

Much appreciated for the help.

1 Like