Meal Maker length not defined

So I’ve been trying to figure out my code for the last 2 hours. I’m making the Meal Maker in the Full Stack career path. I get an error saying that dishes.length is not defined. Please note that I have replaced desserts in the exercise by drinks.

const menu = {
 _course : {
   appetizers : [],
   mains : [],
   drinks : [],
 get appetizers(){
   return this._course.appetizers
 get mains(){
   return this._course.mains
 get drinks(){
   return this._course.drinks
 set appetizers(appetizersIn){
   this._course.appetizers = appetizersIn
 set mains(mainsIn){
   this._course.mains = mainsIn
set drinks(drinksIn){
   this._course.drinks = drinksIn
get courses(){
  return {
    appetizers : this.appetizers ,
     mains : this.mains , 
     drinks : this.drinks ,
addDishToCourse(courseName, dishName , dishPrice){
const dish = {
  name : dishName,
  price : dishPrice,
return this._course[courseName].push(dish);

getRandomDishFromCourse(courseName) {
    const dishes = this._course[courseName];
    const randomIndex = Math.floor(Math.random() * dishes.length);
    return dishes[randomIndex];
  const appetizer = menu.getRandomDishFromCourse(this.appetizers)
  const main = menu.getRandomDishFromCourse(this.mains)
  const drink = menu.getRandomDishFromCourse(this.drinks)
  let totalPrice = appetizer.price + main.price + drink.price
  return `Your meal is : ${appetizer}, ${main} and ${drink}. It will cost a total of ${totalPrice}.`
menu.addDishToCourse('appetizers', 'Calamari', 17.00);
menu.addDishToCourse('appetizers', 'Baked Brie', 16.00);
menu.addDishToCourse('appetizers', 'Baked Garlic Shrimp', 13.00);
menu.addDishToCourse('mains', 'Steak and Shrimp', 50.00);
menu.addDishToCourse('mains', 'Filet Mignon', 51.00);
menu.addDishToCourse('mains', 'Rib Steak', 54.00);
menu.addDishToCourse('drinks', 'Ceasar', 8.00);
menu.addDishToCourse('drinks', 'Watermelon Cosmo', 8.00);
menu.addDishToCourse('drinks', 'BlackBerry Daiquiri', 9.00);
let meal = menu.generateRandomMeal();

You should take a step back and think about the process for debugging this.

  • Your error is talking about dishes.length.
  • dishes.length appears in the getter method: getRandomDishFromCourse(courseName)
  • you declare dishes using a parameter.
  • does this declaration work? Console log to find out.
  • What happens if you just console log the parameter??
  • What type of data is the parameter? if in doubt, check with the typeof method?
  • What type of data does the accessor for this._course need? If in doubt, try accessing data from it with some test command.
1 Like

Thank you for your process ! I’ve found the error. in my generateRandomMeal() function I was using this.appetizers as my parameter, I just needed to use ‘appetizers’ instead!