const menu ={
_menu: '',
_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 Meal is ${this._meal} for $${this._price}!`
}else{
return `Meal or price was set crrectly!`
}
}
};
menu.meal = 'pizza'
menu.price = 5
console.log(menu.todaysSpecial);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter