<script>
var queue = new Array (); Ticket purchase Queue
function client (name)//Customer Object
{
THIS.name = name; Customer Name
This.ticket = NaN; Ticket Number
}
Queue.push (New Client ("Lily"), New Client ("Peter"), New Client ("Vicky"), New Client ("Tom"), New Client ("Jakson")); Queue a customer
Tickets = 4; Number of stock votes
for (;((queue.length!=0) && (tickets!=0);)//Always on sale until no one or ticket has been sold out of the team.
{
var current = Queue.shift (); The first person to get a ticket has left the team.
Current.ticket = tickets;
document.write ("<br> sold; +current.name+", serial number "+tickets"); Output customer information of purchased tickets
Tickets--; Sell one, inventory minus one
}
Alert ("Sales stop, now there are" +queue.length+ "people, and" +tickets+ "tickets! ");
</script>
Simulate the customer queue in front of the ticket window, the first person in the queue to buy the ticket. Customers who have already bought tickets are out of the team, and when the inventory is sold out or the team stops selling.