title: Difficulty Iterating Through Function Call - First Class Functions
body: <p>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.</p>
  <p>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.</p>
  <p>All suggestions are greatly appreciated.</p>
  <p>JS:</p>
  <pre><code>var guests = [
      {name: &quot;Rick Sanchez&quot;, paid: false, loyaltyCard: true},
      {name: &quot;Morty Smith&quot;, paid: true, loyaltyCard: true},
      {name: &quot;Beth Smith&quot;, paid: true, loyaltyCard: false},
      {name: &quot;Jerry Smith&quot;, paid: true, loyaltyCard: false},
      {name: &quot;Sleepy Gary&quot;, paid: true, loyaltyCard: false},
      {name: &quot;Summer Smith&quot;, paid: true, loyaltyCard: false},
      {name: &quot;Mr. Poopybutthole&quot;, paid: true, loyaltyCard: true},
      {name: &quot;Pencilvester&quot;, 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(&quot;Would you like any premium refreshments from our Membership Menu, at no extra cost?&quot;);
          };
      } else {
          orderFunction = function() {
              alert(&quot;Can we get you any refreshments?&quot;);
          };
      }
      return orderFunction;
  }
  
  function serveAllGuests(guests) {
      for (var i = 0; i &lt; guests.length; i++) {
          serveGuest(guests[i]);
      }
  }
  
  serveAllGuests(guests);
  
  
  </code></pre>