Meal Maker :Math.floor(Math.random() * dishes.length()) TypeError: dishes.length is not a function

For the project Meal Maker (Link: Learn JavaScript | Codecademy
I have been getting the same error that reads /home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:34 let X = Math.floor(Math.random() * dishes.length())
^TypeError: dishes.length is not a function

Ive been trying to correct the error for hours but it somehow circles back to dishes.length not being a function. Any help would be appreciated! here is my code

let menu = { _courses: { mains: [], apps: [], deserts: [], }, get apps() {return this._courses.apps}, get mains() {return this._courses.mains}, get deserts() {return this._courses.deserts}, set deserts(desertsIn) { = desertsIn}, set apps(appsIn) { = appsIn}, set mains(mainsIn) { = mainsIn}, get courses () {return { apps: this.apps, mains: this.mains, deserts: this.deserts}}, addDishToCourse: function (courseName, dishName, dishPrice) {const dish = { name: dishName, price: dishPrice, }; return this._courses[courseName].push(dish); }, getRandomDishFromCourse: function (courseName) { let dishes =[courseName] let X = Math.floor(Math.random() * dishes.length()) return dishes[X] }, generateRandomMeal() { const appetizer = this.getRandomDishFromCourse('apps'); const main = this.getRandomDishFromCourse('mains'); const desert = this.getRandomDishFromCourse('deserts'); const totalPrice = appetizer.price + main.price + desert.price; return `The meal is ${}, ${} and desert ${}. Total price ${totalPrice}`; } } menu.addDishToCourse("apps", "bread", 3); menu.addDishToCourse("apps", "tacos", 5) menu.addDishToCourse("apps", "mozerella sticks", 8) menu.addDishToCourse("mains", "chicken", 12) menu.addDishToCourse("mains", "soup", 11) menu.addDishToCourse("mains", "Nachos", 13) menu.addDishToCourse("deserts", "icecream cookie", 3) menu.addDishToCourse("deserts", "pie", 4) menu.addDishToCourse("deserts", "cake", 5) let meal = menu.generateRandomMeal()

Hi @beta4363238168
.length is indeed a property of an array and not a method like .random(). Which means you do not invoke it by adding parenthesis to it.

Wow. I cant believe I did not catch that. I was up until 3am trying to figure it out and I just gave up. Thank you so much!

1 Like