Continuing the discussion from Meal Maker JS Project - help needed :
I had a similar problem but my code uses the assignment =
, can someone tell me why my code always returns the string ‘Meal or price was not set correctly!’ ?
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 = 'lasagna';
menu.price = 11;
console.log(menu.todaysSpecial);