This Codecademy exercise has me creating setters to prevent object properties from being set with incorrect data types. As far as I can tell, my code matches exactly what Codecademy’s “get unstuck” video shows and yet I am still able to set my object properties to whatever data types I want. When I print, it should return ‘Meal or price was not set correctly’ but instead it prints “today’s special is 10 for burger dollars!” There are no errors messages, what am I missing?
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} dollars!
} else {
return ‘Meal or price was not set correctly!’
}
}
};
menu._meal = 10;
menu._price = ‘Burger’;
console.log(menu.todaysSpecial)