Meal Maker printing [object Object]

Hello!

I am encountering an error on the JS object Meal Maker project. Here is the link: https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-javascript-syntax-part-ii/modules/fecp-learn-javascript-syntax-objects/projects/meal-maker

My code is printing:

Your meal includes [object Object], [object Object], and [object Object] and the total price is 20.

It should be printing the names of the selected dishes. I cannot figure out where my problem is! Any insight would be much appreciated.

Here is my code:

//object for whole menu const menu = { //arrays of menu items _courses: { appetizers: [], mains: [], desserts: [], }, //getting and setting functions for each course to fill up array get appetizers() { return this._courses.appetizers; }, set appetizers(appetizerIn){ this._courses.appetizers = appetizers; }, get mains() { return this._courses.mains; }, set mains(mainIn){ this._courses.mains = mains; }, get desserts() { return this._courses.desserts; }, set desserts(dessertIn){ this._courses.desserts = desserts; }, //combines all 3 courses get courses() { return { appetizers: this.appetizers, mains: this.mains, desserts: this.desserts } }, //allows you to add dishes into menu addDishToCourse (courseName, dishName, dishPrice) { const dish = { name: dishName, price: dishPrice, }; //test log //console.log(`courseName is: ${courseName}`); return this._courses[courseName].push(dish); }, //provides random selection of dish in course getRandomDishFromCourse (courseName) { let dishes = this._courses[courseName]; const randomIndex = Math.floor(Math.random() * dishes.length); return dishes[randomIndex]; }, //combines all 3 courses generateRandomMeal() { const appetizer = this.getRandomDishFromCourse('appetizers'); const main = this.getRandomDishFromCourse('mains'); const dessert = this.getRandomDishFromCourse('desserts'); //totals price const totalPrice = (appetizer.price + main.price + dessert.price); return `Your meal includes ${appetizer}, ${main}, and ${dessert} and the total price is ${totalPrice}.`; } }; menu.addDishToCourse('appetizers','Caesar Salad', 4); menu.addDishToCourse('appetizers','Cobb Salad', 5); menu.addDishToCourse('appetizers','Pretzel Sticks', 6); menu.addDishToCourse('mains','Buffalo Wings', 10); menu.addDishToCourse('mains','Cheeseburger', 12); menu.addDishToCourse('mains','Noodles', 8); menu.addDishToCourse('desserts','Tiramisu', 6); menu.addDishToCourse('desserts','Pie', 7); menu.addDishToCourse('desserts','Ice Cream', 6); const meal = menu.generateRandomMeal(); console.log(meal);

I think cos you’re not referencing to a property, but to the whole object (w price and name properties). Notice that on line 58 you call your price w .price, but you don’t call your .name to get the dish name in line 59 (logging the meal)

1 Like