In the Meal maker project I cant display total price because I am getting the type error message which says price is not defined.
here is the link to the exercise. https://www.codecademy.com/paths/web-development/tracks/web-dev-js-arrays-loops-objects/modules/learn-javascript-objects/projects/meal-maker
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(appetizers){
return this._courses.appetizers = appetizers
},
set mains(mains){
return this._courses.mains = mains
},
set desserts(desserts){
return this._courses.desserts = desserts
},
get courses(){
return {
appetizers:this.appetizers,
mains:this.mains,
desserts:this.desserts
}
},
addDishToCourse(courseName, dishName, dishPrice){
const dish = {
name:this.dishName,
price:this.dishPrice
}
return this._courses[courseName].push(dish)
},
getRandomDishFromCourse(courseName){
const dishes = this._courses[courseName]
const randomIndex = Math.floor(Math.random()*dishes.length)
return dishes[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}, ${dessert.name}, ... The price is ${totalPrice}`
},
}
menu.addDishToCourse('mains', 'Rice', 20)
let meal = menu.generateRandomMeal()
console.log(meal)