Meal Maker project - getting a weird output


I’ve cobbled my way through this and pleased that I’m not getting errors buuuuuuut I’m also not getting the right result.

Here’s the project link.

Here’s what I’m getting when I run it:

Your meal will be [object Object], followed by [object Object], and finally [object Object] for dessert. The total cost will be $NaN. Don't forget to tip.

I added a line to check the contents of menu._courses and it shows the name and price values as undefined so I reckon the issue is somewhere with getters and setters but after an hour of scratching my head I could use some more experienced eyes on it.

Here’s my code:

const menu = {
  _courses: {
    appetizers: [],
    mains: [],
    desserts: []
  get appetizers() {
    return this._courses.appetizers;
  set appetizers(appetizerIn) {
    this._courses.appetizers = appetizerIn;
  get mains() {
    return this._courses.mains;
  set mains(mainIn) {
    this._courses.mains = mainIn;
  get desserts() {
    return this._courses.desserts;
  set desserts(dessertIn) {
    this._courses.desserts = dessertIn;
  get courses() {
    return {
      appetizers: this.appetizers,
      mains: this.mains,
      desserts: this.desserts 
  addDishToCourse(courseName, dishName, dishPrice) {
    const dish = {
      name: this.dishName,
      price: this.dishPrice
    return this._courses[courseName].push(dish);  
  getRandomDishFromCourse(courseName) {
    const dishes = this._courses[courseName];
    const randomIndex = Math.floor(Math.random() * dishes.length);
    return dishes[randomIndex]
  generateRandomMeal() {
    const appetizer = this.getRandomDishFromCourse('appetizers');
    const main = this.getRandomDishFromCourse('mains');
    const dessert = this.getRandomDishFromCourse('desserts');
    const totalPrice = appetizer.price + main.price + dessert.price;
    return `Your meal will be ${appetizer}, followed by ${main}, and finally ${dessert} for dessert. The total cost will be $${totalPrice}. Don't forget to tip.`;
menu.addDishToCourse('appetizers', 'Nachos', 9);
menu.addDishToCourse('appetizers', 'Onion Rings', 7);
menu.addDishToCourse('appetizers', 'Skrimpz', 12);
menu.addDishToCourse('mains', 'Chicken', 12);
menu.addDishToCourse('mains', 'Steak', 15);
menu.addDishToCourse('mains', 'Lobster', 25);
menu.addDishToCourse('desserts', 'Cheesecake', 8);
menu.addDishToCourse('desserts', 'Ice Cream', 6);
menu.addDishToCourse('desserts', 'a single Otter Pop', 1);
let meal = menu.generateRandomMeal();

Any help appreciated, pretty please and thanks!

I’ve run your code, and as you can see from the result of logging menu._courses to the console, you have an issue with your addDishToCourse method. You can use an additional console.log() to visualize the problem:

  addDishToCourse(courseName, dishName, dishPrice) {
    // Add the following:
    console.log(`this.dishName: ${this.dishName}  this.dishPrice: ${this.dishPrice}`)
    const dish = {
      name: this.dishName,
      price: this.dishPrice
    return this._courses[courseName].push(dish);  
1 Like

Many thanks! I finally drilled it down to using the wrong references in my return string in generateRandomMeal().


was wrong, corrected to



Following which properties refer to what and where gets totally murky on me. Time for more practice. Thanks again.

1 Like

That would have been where I went next. Good job figuring it out.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.