Simple JavaScript Lucky Draw code and js Lucky Draw

Source: Internet
Author: User

Simple JavaScript Lucky Draw code and js Lucky Draw

Core: js Math objects and Array objects

<!DOCTYPE html>
<html lang="en">
 <meta charset="UTF-8">
  #awardListDom{width: 100%;}
 <label for="awardListDom">Award List</label><br>
 <input type="text" value="" id="awardListDom"> <br>
 <label for="num">The prize drawn</label><br>
 <input type="text" value="" id="num"> <br>
 <button id="submit">Start lottery draw</button>
  * Idea: Random draw, one prize will be reduced by one
  * Math object method:
  * -random(): returns a random number between 0 and 1.
  * -floor(): Get integer
  * Array operation:
  *-splice(x,y); x: starting position, y: get and delete the number

  function random(min,max){
    return Math.floor(min+Math.random()*(max-min));
  var awardListDom=document.getElementById("awardListDom"),
  var awardList=["First Prize","Second Prize","Second Prize","Third Prize","Third Prize","Third Prize","Encouragement Prize","Encouragement Prize", "Encouragement Award", "Encouragement Award", "Thank you for Participating", "Thank you for Participating", "Thank you for Participating", "Thank you for Participating", "Thanks for Participating", "Thank you for Participating"];

   //Reference array
   var oldArray=awardList;
   var rNum=random(0,oldArray.length);
    awardListDom.value="Activity end";
    num.value="Activity end";
Related Article

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