title: How can I use a variable as an index inside of an object? (Javascript)
body: <p>I am trying to use the variables appetizer, main, and dessert as indexes to an array but I cannot figure out how to do this. This is on line 49.</p>
  
  <pre><code>    var 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.desserts = desserts;
    },
  set mains(mains) {
     this.mains = mains;
  },
  set desserts(desserts) {
       this.desserts = desserts;
    },
    get courses() {
      return {
        appetizers,
        mains,
        desserts,
      };
    },
    addDishToCourse (courseName, dishName, dishPrice) { 
     const dish = {
       food: courseName,
       name: dishName,
       price: dishPrice,
  
     };
    return this._courses[courseName].push(dish);
    },
       getRandomDishFromCourse: function(courseName) {
      var dishes = this._courses[courseName];
       if (dishes !== undefined) {
         var randomIndex = Math.floor(Math.random() * dishes.length);
        return randomIndex;
       }
    },
  
    generateRandomMeal: function() { //This is the problem.
     var appetizer = this.getRandomDishFromCourse('appetizers');
      var main = this.getRandomDishFromCourse('mains');
      var dessert = this.getRandomDishFromCourse('dessert');
      return 'Your meal is ' + appetizer + ', ' + main + ', and ' + dessert + '. The total price is $' +/* this.dish.price */ 8 + '.'; 
    }
  }; 
  
  menu.addDishToCourse('appetizers', 'Bread Loaf', 4.25);
  menu.addDishToCourse('appetizers', 'Caesar Salad', 3.50);
  menu.addDishToCourse('appetizers', 'Small Soup', 4.50);
  menu.addDishToCourse('mains', 'Steak Dinner', 20.00);
  menu.addDishToCourse('mains', 'spaghetti', 16.00);
  menu.addDishToCourse('mains', 'Turkey Dinner', 18.99);
  menu.addDishToCourse('desserts', 'Icecream', 5.99);
  menu.addDishToCourse('desserts', 'Cookies', 5.99);
  menu.addDishToCourse('desserts', 'Jello', 5.99);
  
  
  var meal = menu.generateRandomMeal();
  console.log(meal);
  </code></pre>
  
  <p>I have tried to use this code:</p>
  
  <pre><code>this.appetizers[appetizer]
  this.mains[main]
  this.desserts[dessert]
  </code></pre>
  
  <p>but this just returns Object object in place of the index number. </p>