I just completed the Meal Maker project from Intro to JavaScript. I can’t figure out why the setters aren’t working correctly. I’ve looked at videos and examples, but I seem to have written my code the same way. Any help is appreciated!
const menu = {
_meal: " ",
_price: 0,
set meal(mealToCheck) {
if (typeof mealToCheck === "string") {
return (this._meal = mealToCheck);
}
},
set price(priceToCheck) {
if (typeof priceToCheck === "number") {
return (this._price = priceToCheck);
}
},
get todaysSpecial() {
if (this._meal && this._price) {
return `Today's Special is ${this._meal} for $${this._price}!`;
} else {
return "Meal or price was not set correctly!";
}
},
};
menu._meal = 'pizza';
menu._price = 12;
console.log(menu.todaysSpecial);