Meal Maker help (Full-Stack Software Engineer Path)

I’m so lost as to what is causing this. I know it’s probably some silly punctuation error causing a function to keep going on itself or something but I am so tired for the day lol. Could somebody tell me if they see what’s happening here or point me in the right direction so I don’t hit a wall when I pick back up the studies tomorrow? Please and thank you :grin:

const menu = { _courses: { appetizers: [], mains: [], desserts: [], }, get appetizers() { return this._courses.appetizers; }, get mains() { return this._courses.mains; }, get desserts() { return this._courses.desserts; }, set appetizers(appetizers) { this._courses.appetizers = appetizers; }, set mains(mains) { this._courses.mains = mains; }, set desserts(desserts) { this._courses.desserts = desserts; }, get _courses() { return { appetizers: this.appetizers, 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[randomIndex]; }, generateRandomMeal() { const appetizer = this.getRandomDishFromCourse('appetizers'); const main = this.getRandomDishFromCourse('mains'); const dessert = this.getRandomDishFromCourse('desserts'); const totalePrice = appetizer.price + main.price + dessert.price; return `Your meal is ${appetizer.name}, ${main.name}, and ${dessert.name}. The price is ${totalPrice}.`; } }; menu.addDishToCourse('appetizers', 'mozzarella sticks', 4.59); menu.addDishToCourse('appetizers', 'jalepeno poppers', 4.99); menu.addDishToCourse('appetizers', 'bread', 3.29); menu.addDishToCourse('mains', 'chicken', 7.59); menu.addDishToCourse('mains', 'steak', 8.59); menu.addDishToCourse('mains', 'duck', 9.99); menu.addDishToCourse('desserts', 'ice cream sundea', 3.29); menu.addDishToCourse('desserts', 'pie', 3.99); menu.addDishToCourse('desserts', 'cake', 3.59); const meal = menu.generateRandomMeal(); console.log(meal);

I found a problem:

get _courses() {

should be

get courses() {

otherwise you’re replacing the _courses you defined previously
which results in an infinite recursion somewhere.

Also, total is misspelled.

In this case it is not recursion as much as a circular reference which does not have a call stack, just two references to each other. You are right that the getter needs to be treated as a separate property and only binds its return to the backing property.

get courses () {
    return this._courses;
}
1 Like

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