Https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-javascript-syntax-part-ii/modules/fecp-learn-javascript-syntax-objects/projects/meal-maker

Can someone explain???When i use dot notation its showing typeerror, but when i use bracket notation its working fine.I thought that braket notation is used for keys which are strings ? pls see on the commented lines

let 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(item){

      this._courses.appetizers = item

    },  

    set mains(item){

      this._courses.mains = item

    }, 

    set desserts(item){

      this._courses.desserts = item

    },

    get courses(){

      return {

        appetizers : this.appetizers,

        mains : this.mains,

        desserts : this.desserts

      }

    },

addDishToCourse (courseName,dishName,dishPrice){

const dish = {

  price:dishPrice,

  dishName:dishName

  }

  this._courses[courseName].push(dish) // if i use this._courses.courseName.push(dish) it shows typeerror

},

getRandomDishFromCourse(courseName){

const dishes = this._courses[courseName]; // if i use this._courses.courseName it shows type error

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

  

  return dishes[randomIndex]

},

generateRandomMeal(){

  const appetizers = this.getRandomDishFromCourse('appetizers')

  const mains = this.getRandomDishFromCourse('mains')

  const desserts = this.getRandomDishFromCourse('desserts')

  let price = appetizers.price+mains.price+desserts.price

  return `Total Price is ${price} for ${appetizers.dishName} , ${mains.dishName} , ${desserts.dishName}}`

}

}

menu.addDishToCourse('appetizers', 'Caesar Salad', 4.25);

menu.addDishToCourse('mains', 'Biriyani', 10.25);

menu.addDishToCourse('desserts', 'Payasam', 10.50);

console.log(menu.generateRandomMeal())

courseName variable holds a string value? You can’t pass properties as arguments to methods or functions

so you have to use the associative array notation (the square brackets)

Ok now i get it , Thanks