Meal Maker Project Range Error message

In the Meal Maker project in JavaScript (link) I’m having difficulty figuring out a Range Error that I’m getting.
I can see from the error that line 26 is creating a looping problem that just keeps going over _courses and appetizers, but I can’t figure out how to fix it. I’ve seen another person on here have the same problem, but didn’t really understand the solution.

The thing that is really throwing me is that I looked over the walkthrough video (link) and my code follows it almost to the letter (and is the same on line 26), with the significant difference being that their code works while mine throws the Range Error.

Can someone help spell this out for me? I’m clearly missing something.
My code is:

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 randomDish = Math.floor(Math.random()*dishes.length); return dishes[randomDish]; }, generateRandomMeal(){ const appetizer = this.getRandomDishFromCourse('appetizers'); const main = this.getRandomDishFromCourse('mains'); const dessert = this.getRandomDishFromCourse('desserts'); const totalPrice = appetizers.price + mains.price + desserts.price; return `You meal cost ${totalPrice}`; } }; menu.addDishToCourse('appetizers', 'potato skins', 4); menu.addDishToCourse('appetizers', 'salad', 3); menu.addDishToCourse('appetizers', 'nachos', 5); menu.addDishToCourse('mains', 'salmon', 8); menu.addDishToCourse('mains', 'chicken', 7); menu.addDishToCourse('mains', 'surf and turf', 10); menu.addDishToCourse('desserts', 'cake', 2); menu.addDishToCourse('desserts', 'pie', 2); menu.addDishToCourse('desserts', 'smoothie', 2); const meal = menu.generateRandomMeal(); console.log(meal);

Hello!
hint: have a look at the hint for task 6 and compare it to what you’ve written.

your getter is repeatedly calling the object
it should just be ‘courses’ on line 25. i.e. no ‘_’

1 Like

Oof. That’s so obvious it almost hurts.
I looked over the code so much I went blind apparently.
Thank you so much for your help.
Here is the fixed code for anyone else who might run across this problem:

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 randomDish = Math.floor(Math.random()*dishes.length); return dishes[randomDish]; }, 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 `You meal cost ${totalPrice}, you will be served ${appetizer.name}, ${main.name}, and ${dessert.name}.`; } }; menu.addDishToCourse('appetizers', 'potato skins', 4); menu.addDishToCourse('appetizers', 'salad', 3); menu.addDishToCourse('appetizers', 'nachos', 5); menu.addDishToCourse('mains', 'salmon', 8); menu.addDishToCourse('mains', 'chicken', 7); menu.addDishToCourse('mains', 'surf and turf', 10); menu.addDishToCourse('desserts', 'cake', 2); menu.addDishToCourse('desserts', 'pie', 2); menu.addDishToCourse('desserts', 'smoothie', 2); const meal = menu.generateRandomMeal(); console.log(meal);
1 Like