Develop queue that holds objects in line with Java script

Hello,

I have a javascript file and I am trying develop a queue that holds an object in line and then assigns that object to a 'coffee maker' when one becomes open.  Thanks for the help.
Here is  my code.
function sendRequest(request, url) {
  request.onreadystatechange = serveDrink;
  request.open("GET", url, true);
  request.send(null);
}


function getSize() {
  var sizeGroup = document.forms[0].size;
  for (i=0; i<sizeGroup.length; i++) {
    if (sizeGroup[i].checked == true) {
      return sizeGroup[i].value;
    }
  }
}

function getBeverage() {
  var beverageGroup = document.forms[0].beverage;
  for (i=0; i<beverageGroup.length; i++) {
    if (beverageGroup[i].checked == true) {
      return beverageGroup[i].value;
    }
  }  
}

function orderCoffee() {
  var name = document.getElementById("name").value;
  var beverage = getBeverage();
  var size = getSize();

  var coffeemakerStatusDiv1 = 
   document.getElementById("coffeemaker1-status");
  var status = getText(coffeemakerStatusDiv1);
  if (status == "Idle") {
    replaceText(coffeemakerStatusDiv1, "Brewing " + name + "'s " +
                size + " " + beverage);
    // clear the form        
    document.forms[0].reset();
    var url = "coffeemaker.php?name=" + escape(name) +
                             "&size=" + escape(size) +
                             "&beverage=" + escape(beverage) +
                             "&coffeemaker=1";
    sendRequest(request1, url);
  } else {
    var coffeemakerStatusDiv2 =
      document.getElementById("coffeemaker2-status");
    status = getText(coffeemakerStatusDiv2);
    if (status == "Idle") {
      replaceText(coffeemakerStatusDiv2, "Brewing " + name + "'s " +
                  size + " " + beverage);
      document.forms[0].reset();
      var url = "coffeemaker.php?name=" + escape(name) +
                               "&size=" + escape(size) +
                               "&beverage=" + escape(beverage) +
                               "&coffeemaker=2";
      sendRequest(request2, url);
      
    } else {
      alert("Sorry! Both coffee makers are busy. " +
            "Try again later.");
    }
  }
}
// return text similar to 1Mary for Mary's order in coffer maker #1
// return text similar to 1Mary for Mary's order in coffer maker #1
function serveDrink() {
  if (request1.readyState == 4 || request2.readyState == 4) {
    if (request1.status == 200 || request2.status == 200)  {
	// we can proceed since one of the two coffee makers returned a ready state of 4 and a status of 200.
	//now we need to find out which one it was and store it in the variable response
        var response;
      if(request1.readyState == 4 )
        response = request1.responseText;
      else if(request2.readyState == 4 )
         response = request2.responseText;
    
      // get the number of the coffee maker
      var whichCoffeemaker = response.substring(0, 1);
      // get the user's name
      var name = response.substring(1, response.length);
      if (whichCoffeemaker == "1") {
        var coffeemakerStatusDiv1 = 
          document.getElementById("coffeemaker1-status");
        replaceText(coffeemakerStatusDiv1, "Idle");
		request1 = createRequest();
      } else if (whichCoffeemaker == "2"){
        var coffeemakerStatusDiv2 = 
          document.getElementById("coffeemaker2-status");
        replaceText(coffeemakerStatusDiv2, "Idle");
		request2 = createRequest();
      }
      alert(name + ", your coffee is ready!");
      //this next lines resets the request object's ready state
      // we do not want it to stay at 4 or the second one would never
      // get served (the if's above would remain true)
      // JavaScript cannot directly set the readyState property to zero
      request1 = createRequest();
    } else 
      alert("Error! Request status is " + request1.status);
  } 
  }

Open in new window

LVL 1
capturetheflagAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

capturetheflagAuthor Commented:
Hello,

I am trying to use the following code develop a queue.
var queue = [];
queue.add = queue.push;
queue.remove = queue.shift;

queue.add(1);
var i = queue.remove();
alert(i);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
capturetheflagAuthor Commented:
Done done.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.