The code I have provided executes properly, however as you will see it offers refreshments to each guest repeatedly before moving on to the next guest.
I'm scratching my head as to how I can alter my code, in an efficient way, so that each customer is offered refreshments in turn, but still attended to four times each when the program is run.
All suggestions are greatly appreciated.
JS:
var guests = [
{name: "Rick Sanchez", paid: false, loyaltyCard: true},
{name: "Morty Smith", paid: true, loyaltyCard: true},
{name: "Beth Smith", paid: true, loyaltyCard: false},
{name: "Jerry Smith", paid: true, loyaltyCard: false},
{name: "Sleepy Gary", paid: true, loyaltyCard: false},
{name: "Summer Smith", paid: true, loyaltyCard: false},
{name: "Mr. Poopybutthole", paid: true, loyaltyCard: true},
{name: "Pencilvester", paid: true, loyaltyCard: false}
];
function serveGuest(guest) {
var getRefreshmentOrder = createRefreshmentOrder(guest);
getRefreshmentOrder();
// Loyalty Stamps
getRefreshmentOrder();
getRefreshmentOrder();
// Agressive Advertisment
getRefreshmentOrder();
// Thank you. Come again.
}
function createRefreshmentOrder(guest) {
var orderFunction;
if (guest.loyaltyCard) {
orderFunction = function() {
alert("Would you like any premium refreshments from our Membership Menu, at no extra cost?");
};
} else {
orderFunction = function() {
alert("Can we get you any refreshments?");
};
}
return orderFunction;
}
function serveAllGuests(guests) {
for (var i = 0; i < guests.length; i++) {
serveGuest(guests[i]);
}
}
serveAllGuests(guests);