JS Draw function Code

Source: Internet
Author: User

Html
<label for= "awardlistdom" > Awards list </label><br><input type= "text" value= "" id= "Awardlistdom" > <br><label for= "num" > Drawn award </label><br><input type= "text" value= "" id= "num" > <br> <button id= "Submit" > Start draw </button>
Js
<script>  function Random (Min,max) {    return Math.floor (Min+math.random () * (max-min));  }  var Awardlistdom=document.getelementbyid ("Awardlistdom"),  Num=document.getelementbyid ("num"),  submit= document.getElementById ("submit");  var awardlist=["First Prize", "Second Prize", "Second Prize", "Third Prize", "Third Prize", "Third prize", "Encouragement Award", "Encouragement Award", "Encouragement Award", "Encouragement Award", "Thank You for participation", "Thank You for participation", "Thank You for participation", "Thank you for participating" Thank you for participating "];  Awardlistdom.value=awardlist;  Submit.onclick=function () {   //reference array   var oldarray=awardlist;   var rnum=random (0,oldarray.length);      if (oldarray.length<1) {    awardlistdom.value= "activity ends";    Num.value= "activity ends";   }   else{    Num.value=oldarray[rnum];    Oldarray.splice (rnum,1);    Awardlistdom.value=oldarray;   }  } </script>

Core:

JS's Math object and array object

Ideas:

1. Draw a prize and reduce a 2.Math object method: Http://www.w3school.com.cn/jsref/jsref_obj_math.asp 3.-random (): Returns the random number between 0 and 1. 4.-floor (): Get integer

Array operations:

-Splice (x, y); X: Start position, y: Get and delete number

  

JS Draw function Code

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.