Meal Maker RangeError: Maximum call stack size exceeded

I keep getting this RangeError at ‘return {’ in get _courses(). I’ve tried watching the video and googling my issue but I can’t figure out what’s wrong. There may be more than one issue with my code, it’s a big mess. Any help would be appreciated! Thank you! :slight_smile:

let menu = {
  _courses: {
    appetizers: [],
    get appetizers() {
      
    },
    mains: [],
    get mains() {
      
    },
    desserts: [],
    get desserts() {
      
    }
  },
  get _courses() {
    return {
      appetizers: this._courses.appetizers,
      mains: this._courses.mains,
      desserts: this._courses.desserts
    }
  },
  addDishToCourse(courseName, dishName, dishPrice) {
    const dish = {
      name: dishName,
      price: dishPrice
    }
    this._courses[courseName].push(dish);
  },
  getRandomDishFromCourse(courseName) {
    const dishes = this._courses.courseName;
    const randomNum = Math.floor(Math.random(dishes.length()))
    return dishes[randomNum]
  },
  generateRandomMeal() {
    const appetizer = menu.getRandomDishFromCourse(appetizers);
    const main = menu.getRandomDishFromCourse(mains);
    const dessert = menu.getRandomDishFromCourse(desserts);
    const price = appetizer.price + main.price + dessert.price
    return appetizer, main, dessert, price
  }
}

menu.addDishToCourse('appetizers', 'fish', 9)
menu.addDishToCourse('appetizers', 'taco', 8)
menu.addDishToCourse('appetizers', 'beef', 7.5)

Haven’t looked at your code thoroughly, but to start with, changing get _courses() {} to get courses() {} will clear the RangeError. By having get _courses() you’re creating a circular reference. See where it goes from there. Happy Coding.

2 Likes

You also need to rearrange the beginning of your menu object. Should look similar to this:

let menu = { //opening menu object curly brace
  _courses: {
    appetizers: [],
    mains: [],
    desserts: []
  }
  //getters, setters and methods follow here
} //closing menu object curly brace

Thank you so much! I think I’m going to reset the project and start over using this. :slight_smile:

1 Like

I’m not sure starting over is necessary, but it may help as far as learning and retaining the material goes. Good luck, and feel free to ask if you need further assistance. Happy coding!!

2 Likes

What actually gets returned of the above? JS doesn’t support comma separated returns, as far as I know.

 > function returns() {
     a = 6;
     b = 7;
     c = a * b;
     return a, b, c;
   }
<- undefined
 > returns()
<- 42
 > function returns() {
     a = 6;
     b = 7;
     c = a * b;
     return c, b, a;
   }
<- undefined
 > returns()
<- 6

I too had the problem above and this little trick fixed it right away! Nice :+1: Thank you!