-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhile.html
59 lines (51 loc) · 1.92 KB
/
while.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!-- 骰遊戲 -->
<button id="good">start</button> <button>return</button>
<div class="result">結果: <div class="output" id="put"></div></div>
<script>
// document.querySelector('button').addEventListener('click',function(){
// var dice1 =1;
// var dice2 =2;
// var dice3 =3;
// var count = 0;
// while(!(dice1==dice2 && dice2==dice3)){
// count++;
// dice1 = Math.floor(Math.random()*6)+1;
// dice2 = Math.floor(Math.random()*6)+1;
// dice3 = Math.floor(Math.random()*6)+1;
// var starts = document.querySelector('.output');
// starts.innerHTML = `第${count}次骰結果:${dice1},${dice2},${dice3}<br>${starts.innerHTML}`;
// }
// })
document.querySelector('button').addEventListener('click',function(){
var dice1 =1;
var dice2 =2;
var dice3 =3;
var count = 0;
while(true){
count++;
dice1 = Math.floor(Math.random()*6)+1;
dice2 = Math.floor(Math.random()*6)+1;
dice3 = Math.floor(Math.random()*6)+1;
var starts = document.getElementById('put');
starts.classList.add("good");
console.log(starts);
// console.log(starts);
// ${starts.innerHTML}為什麼可以用
// starts.innerHTML = `第${count}次骰結果:${dice1},${dice2},${dice3}<br>${starts.innerHTML}`;
if(dice1==dice2 && dice2==dice3){
break;
}
}
});
</script>
</body>
</html>