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.

Source: Internet
Author: User

<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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.