Issue with Menu Project in Objects: Maximum call stack size exceeded

playing with JavaScript classes and got this problems
kinda was lost and after facing this problem , totally lost :sleepy:

onst menu = {
  _courses: {
    appetizers: [],
    mains: [],
    desserts: [],
  },
  get appetizer(){
      return this._courses.appetizer;

  },
  set appetizers(appetizerIn){
     this._courses.appetizers = appetizers ;

  },
  get mains(){
    return this._courses.mains;

  },
  set mains(mainsIn){
       this._courses.mains = mains ;


  },
  get desserts(){
    return this._courses.desserts;

  },
  set desserts(dessertsIn){
    this._courses.desserts = desserts;
  },


  get _courses(){
    return {
      appetizers: this.appertizers,
      mains: this.mains,
      desserts: this.desserts,
    };
  },


  addDishToCourse(courseName, dishName, dishPrice){
      const dish = {
        name: dishName,
        price: dishPrice,
      };
      return this._courses[courseName].push(dish);

  },


getRandomDishFromCourse(courseName){

  const dishes = this._courses[courseName];
  const randomIndex = Math.floor(math.random()*dishes.length);
  return dishes[randonIndex];

},

generateRandomMeal(){
  const appetizer = this.getRandomDishFromCourse('Appertizers');
  const main = this.getRandomDishFromCourse('Mains');
  const dessert = this.getRandomDishFromCourse('Desserts');
  const totalPrice = appetizer.price + main.price + desert.price;
  return `your meal is ${appetizer.name}, ${main.name}, and ${dessert.name}, and your total price is ${totalprice}`;

},

};


menu.addDishToCourse('appetizers', 'salad', 4);
menu.addDishToCourse('appetizers', 'wings', 4);
menu.addDishToCourse('appetizers', 'fries', 5);

menu.addDishToCourse('mains', 'steak', 10);
menu.addDishToCourse('mains', 'salmon', 7);
menu.addDishToCourse('mains', 'tofu', 11);


menu.addDishToCourse('desserts', 'Ice Cream', 3);
menu.addDishToCourse('desserts', 'coffee', 5);
menu.addDishToCourse('desserts', 'cake', 4);




Hey there

I think get _courses() should be get courses()

this.appertizers is misspelled.

Maybe this is enough to get it running I think.

…they look the same to me; did you mean "should be get courses()" ? :slight_smile:

1 Like

Fixed, exactly right hahahah. My brain just malfunctioned :sweat_smile: :sweat_smile: :sweat_smile: (not the first time).
I’ve never seen the underscore used in a function…

2 Likes