Meal Maker - Step 10 "cannot read property . . ."

Hello,

Been at this for a few hours and can’t seem to get it. I get the error message:

/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:40
const dishes = this._course[courseName];
^

TypeError: Cannot read property ‘appetizers’ of undefined
at Object.getRandomDishFromCourse (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:40:28)
at Object.generateRandomMeal (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:45:28)
at Object. (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:67:19)

Here is my code for the project. I followed the video step-by-step and still had issues.

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(appetizersIn){

  this._courses.appetizers = appetizersIn;

  },

    set mains(mainsIn){

  this._courses.mains = mainIn;

  },

  set desserts(dessertsIn){

this._courses.desserts = dessertsIn;

  },

  get courses (){

return{

  appetizers: this.appetizers,

  mains: this.mains,

  desserts: this.desserts

    };

  },

  addDishToCourse(courseName, dishName, dishPrice){

const dish = {

  name: dishName,

  price: dishPrice

};

this._courses[courseName].push(dish);

  },

  getRandomDishFromCourse(courseName){

const dishes = this._course[courseName];

const randomIndex = Math.floor(Math.random() * dishes.length);

return [randomIndex];

  },

  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 `Your meal is ${appetizer.name}, ${main.name}, and ${dessert.name} and your total is ${totalPrice}.`

  }

//_appetizers:['mushrooms', 'chips', 'wings'],

//_mains: ['burger', 'tacos', 'salad']

//_desserts: ['ice cream', 'cookies', 'pie']

  }

menu.addDishToCourse('appetizers', 'mushrooms', 5.00);

menu.addDishToCourse('appetizers', 'wings', 7.00);

menu.addDishToCourse('appetizers', 'chips', 3.50);

menu.addDishToCourse('mains', 'burger', 8.00);

menu.addDishToCourse('mains', 'salad', 9.00);

menu.addDishToCourse('mains', 'tacos', 7.50);

menu.addDishToCourse('desserts', 'ice cream', 4.00);

menu.addDishToCourse('desserts', 'cookies', 3.00);

menu.addDishToCourse('desserts', 'pie', 6.75);

const meal = menu.generateRandomMeal();

console.log(meal)

Meal Maker Project - Javascript

In the getRandomDishFromCourse function:

You need to fix the line that says:

return [randomIndex]; 

Thank you for that correction. But I’m still getting the same error. Something with my appetizers being undefined?

I figured it out by some really dumb luck after reading other posts about this project.

const dishes = this._course[courseName];

I was missing the ‘s’ at the end of _courses :expressionless:

Thank you @janbazant1107978602 for responding yesterday