const mealsList = ['Banh Mi', 'Pho Bo', 'Mi Quang', 'Com Ga', 'Banh Can'];
const menu = {
_meal: '',
_price: 0,
set meal(mealToCheck) {
if (typeof mealToCheck === 'string') {
this._meal = mealToCheck;
}
},
set price(priceToCheck) {
if (typeof priceToCheck === 'number') {
this._price = priceToCheck;
}
},
get todaysSpecial() {
if (this._meal && this._price) {
return `Today's Special is ${this._meal} for ${this._price} VND!`;
} else {
return 'Meal or price was not set correctly!';
}
}
};
const getRandomMeal = () => {
menu.meal = mealsList[Math.floor(Math.random() * mealsList.length)];
}
getRandomMeal();
menu.price = 25000;
console.log(menu.todaysSpecial);
Do I get an additional task about creating an array right? Looks too simple if so. Should I just create a global array or maybe make a nested object with meals and prices? Please share your solutions below if you made it more complex and interesting. Thanks a lot. Happy journey everyone