Help with meal maker

I need help as i keep getting an error

const menu = {

  _courses: {

    appertizers: [],

    mains: [],

    desserts: []


  get courses(){

    return {

      appertizers: this.appertizers,

      mains: this.mains,

      desserts: this.desserts,



  get appertizers(){

    return this._courses.appertizers


  set appertizers(appertizers){

    this._courses.appertizers = appertizers;


  get mains(){

    return this._courses.mains


  set mains(mains){

    this._courses.mains = mains;


  get desserts(){

    return this._courses.desserts;


  set desserts(desserts){

    this._courses.desserts = desserts;


  addDishToCourse(courseName, dishName, dishPrice){

    const dish = {

      name: dishName,

      price: dishPrice


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



    let dishes = this._courses[courseName];

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

    return dishes[randomIndex];



    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 ${}, ${},  The price is ${totalPrice}.`;




menu.addDishToCourse('appertizers', 'tomato soup', 5.00);

menu.addDishToCourse('mains', 'Beef roast', 10.20);

menu.addDishToCourse('desserts', 'chocolate cake', 5.55);

menu.addDishToCourse('appertizers', 'oxtail soup', 5.20);

menu.addDishToCourse('mains', 'Beef pie', 10.40);

menu.addDishToCourse('desserts', 'lemon cake', 5.55);

menu.addDishToCourse('appertizers', 'pea soup', 5.90);

menu.addDishToCourse('mains', 'Beef hot pot', 10.10);

menu.addDishToCourse('desserts', 'cheese cake', 5.40);

let meal = menu.generateRandomMeal();


this is the error message

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

TypeError: Cannot read property 'length' of undefined
    at Object.getRandomDishFromCourse (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:30:56)
    at Object.generateRandomMeal (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:34:28)
    at Object.<anonymous> (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:53:17)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:427:7)

Hello, @beta1688568499, and welcome to the forums.

In this line, you are trying to call your getRandomDishFromCourse() method with the argument, 'appetizers':

If we look at your method:

The first step is to assign a variable, dishes to the value, this._courses['appetizers'] since 'appetizers' is the argument supplied. Do you have a property in your menu._courses object named 'appetizers'?