用javascript做36选7怎么写

JavaScript023

用javascript做36选7怎么写,第1张

<html >

<head>

<style type="text/css">

.d1{float: left}

</style>

</head>

<body>

<div id="random1" class="d1" style="width:50px">0</div><div id="random2" class="d1" style="width:50px">0</div>

<div id="random3" class="d1" style="width:50px">0</div><div id="random4" class="d1" style="width:50px">0</div>

<div id="random5" class="d1" style="width:50px">0</div><div id="random6" class="d1" style="width:50px">0</div>

<div id="random7" class="d1" style="width:50px">0</div>

<div id="random8" class="d1" style="width:500pxcolor:red">点击开始键摇数字,按暂停键确定数字</div><br/><br/>

<div id="showDiv1" class="d1" style="width:50px">0</div><div id="showDiv2" class="d1" style="width:50px">0</div>

<div id="showDiv3" class="d1" style="width:50px">0</div><div id="showDiv4" class="d1" style="width:50px">0</div>

<div id="showDiv5" class="d1" style="width:50px">0</div><div id="showDiv6" class="d1" style="width:50px">0</div>

<div id="showDiv7" class="d1" style="width:50px">0</div><br/><br/>

<input type="button" value="开始" onclick="beginning()" /> <input type="button" value="暂停" onclick="ending()"/>

<script>

var i=0,timeout,times=0

var divArray = ['random1','random2','random3','random4','random5','random6','random7']

var showArray = ['showDiv1','showDiv2','showDiv3','showDiv4','showDiv5','showDiv6','showDiv7']

function getNum(){return Math.round(Math.random()*36)}

function beginning(){

for(var i = 0i <divArray.lengthi++){document.getElementById(divArray[i]).innerHTML = getNum()}

timeout =setTimeout(beginning,20)

}

function ending(){

if(times <7){

for(var i = 0i <showArray.lengthi++){document.getElementById(showArray[times]).innerHTML = getNum()}

document.getElementById('random8').innerHTML = '第'+(times+1)+'位的数字已产生,为:'+document.getElementById(showArray[times]).innerHTML+',按暂停键继续摇数字!'

times++

}

if(times == 7){document.getElementById('random8').innerHTML = '7个数字生成完毕!'clearTimeout(timeout)}

}

</script>

</body>

</html>

1,html写好界面,定义好class和id

2,为了模拟出扑克牌21点游戏,应先定义卡牌池中有1-10,J,Q,K每个数字和字母分别有4个

3,js中实现界面交互,如点击开始按钮,随机从卡牌池中抽取一个数字或字母存入临时变量a,并附于点数之和num其相应的点数

4,点击抽牌按钮随机从卡牌池剩余的卡牌中抽取,对应的卡牌存入变量a中,点数之和num=num+本次抽卡的点数

5,当num>21时提示玩家爆点,小于21点时可选按钮抽牌,等于21点时提示恭喜之类的话,如果点击完成抽牌则记录此玩家点数

6,同理可扩充玩家至2,3,4....个,原理相同,不同玩家存储对应的变量就可以了,最终通过所有<=21点的玩家num,num1,num2来判断输赢

7,同理可设置庄家,庄家在与其他玩家点数相同时赢得对方

8,在此基础上就能增添许多功能了,比如每个玩家默认100金币,有底注,每轮开始的时候可加注,如玩家不跟则底注输掉无法参加游戏,等等之类的各种规则随便发挥

下面是使用 JavaScript 的 while 循环来输出从 1 到 100 的所有偶数的代码:

let num = 2

while (num <= 100) {

console.log(num)

num += 2

}

在这个代码中,我们声明了一个变量 num 并将其初始值设置为 2。接着,我们使用 while 循环,其中的条件是 num <= 100。每次循环,我们都会输出 num 的值,并将其加上 2。这样,我们就可以在循环内部不断输出所有的偶数,直到 num 大于 100 为止。