当前位置:网站首页>JS to realize simple lottery function
JS to realize simple lottery function
2022-06-30 14:32:00 【Domineering ape General Manager】
1. scene :
Click the button to start randomly drawing prizes , When it stops, what stays on the big screen is the prize (“ thank you ” No award ).
2. Ideas :
as everyone knows , The lottery is mainly about randomness , And it's a collection of awards . Then you can lock the direction : Use the array to award item names , use Math.random() To return between 0( contain ) ~ 1( It doesn't contain ) A random number between . As long as you can randomly select the subscript of the array , You can randomly select awards .
Don't talk much , Attach code :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<button id="start"> Start </button>
<button id="end"> stop it </button>
<h1 id="txt"> Please start </h1>
<script> var ostart=document.getElementById('start'); var oend=document.getElementById('end'); var otxt=document.getElementById('txt'); var timer; var m; var list=[' mobile phone ','pad','pad',' Shopping card ',' Shopping card ',' Shopping card ',' sound ',' thank you ',' thank you ',' thank you ',' thank you ',' thank you ',' thank you ',' thank you ',' thank you ',' thank you '] // Start ostart.onclick=function(){
timer=setInterval(function(){
// Generate random numbers m=parseInt(Math.random()*list.length); // modify html otxt.innerHTML=list[m] // Modify picture .setAttribute('src',list[m]) },1000) } // stop it oend.onclick=function(){
clearInterval(timer); alert(' Congratulations on winning '+list[m]); list.splice(m,1,' thank you '); } </script>
</body>
</html>
Click on “ Start ” Button :
Lucky draw results :
Set the timer by yourself . Try it now !
边栏推荐
- ctfshow nodejs
- Go language mutex lock
- ot initialized – call ‘refresh’ before invoking lifecycle methods via the context: Root WebApplicati
- Not satisfied with markdown native code block style? Try this beautify code screenshot tool~~
- Flat shading with unity
- What network security problems are exposed when a large-scale QQ number theft event occurs?
- Meaning of while (~scanf ("%d%d", & A, & B))
- Talk about Vue's two terminal diff algorithm, analysis of the rendering principle of the mobile terminal, and whether the database primary key must be self incremented? What scenarios do not suggest s
- @ResponseBody的作用
- V3 02——What‘s new in Chrome extensions
猜你喜欢

Introduction to reverse commissioning - VA and RVA conversion in PE 04/07

Laravel configures passport and returns token using JWT

2021 geek challenge Web

Rpm2rpm packaging steps

深入理解.Net中的线程同步之构造模式(二)内核模式4.内核模式构造物的总结

Race of golang

KnightCTF WEB

ThinkPHP show method parameter controllable command execution

Deep understanding Net (2) kernel mode 2 Kernel mode construct semaphone

Heavyweight: the domestic ide was released, developed by Alibaba, and is completely open source!
随机推荐
ot initialized – call ‘refresh’ before invoking lifecycle methods via the context: Root WebApplicati
MySQL back to table query optimization
[observation] as the intelligent industry accelerates, why should AI computing power take the lead?
Vue returns to the previous page without refreshing the page / Vue caches the page
Talk about Vue's two terminal diff algorithm, analysis of the rendering principle of the mobile terminal, and whether the database primary key must be self incremented? What scenarios do not suggest s
I'd like to ask you, where can I open an account in Foshan? Is it safe to open a mobile account?
notepad正则删除关键词所在行
KnightCTF WEB
Notepad regular delete the line of the keyword
Rpm2rpm packaging steps
[buuctf] [actf2020 freshman competition]exec1
1 figure to explain the difference and connection between nodejs and JS
Google Earth engine (GEE) -- converts string to number and applies it to time search (ee.date.fromymd)
数据恢复软件EasyRecovery15下载
Error on datetime when importing SQL file from MySQL
[scientific research data processing] [practice] frequency analysis chart of category variables, distribution chart of numerical variables and normality test (including lognormal)
Is it troublesome for CITIC futures to open an account? Is it safe? How much is the handling charge for opening an account for futures? Can you offer a discount
我想问一下招商证券怎么开户?通过链接办理股票开户安全吗
JS delete the objects in the array and specify to delete the objects
Heavyweight: the domestic ide was released, developed by Alibaba, and is completely open source!