Hi, i’m having trouble finding out what i am doing wrong here, since i’ve pretty much copied what’s in the hint of the project.
Here’s my code:
const menu = {
_courses: {
appetizers: '',
mains: '',
desserts: ''
},
get appetizers () {
return this._courses.appetizers;
},
set appetizers (newAppetizer) {
if(typeof newAppetizer === 'string'){
this._courses.appetizers = newAppetizer;
}
else{
console.log('Please enter a valid string.');
}
},
get mains () {
return this._courses.mains;
},
set mains (newMains) {
if(typeof newMains === 'string'){
this._courses.mains = newMains;
}
else{
console.log('Please enter a valid string.');
}
},
get desserts () {
return this._courses.desserts;
},
set desserts (newDessert) {
if(typeof newDessert === 'string'){
this._courses.desserts = newDessert;
}
else{
console.log('Please enter a valid string.');
}
},
get courses () {
return this._courses;
},
addDishToCourse (courseName, dishName, dishPrice) {
const dish = {
name: dishName,
price: dishPrice
};
this._courses[courseName].push(dish);
},
};
But when i try to run the addDishToCourse method:
menu.addDishToCourse('desserts', 'ice cream', 2.99);
It returns this error:
this._courses[courseName].push(dish);
^
TypeError: this._courses[courseName].push is not a function
at Object.addDishToCourse
Any help will be appreciated.