-
Notifications
You must be signed in to change notification settings - Fork 0
/
homework2.htm
77 lines (50 loc) · 1.23 KB
/
homework2.htm
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html>
<body>
<p>擲骰 1D 6</p>
<button onclick="a()">開始</button>
<p id="dice1"></p>
<p>擲骰 1D 10</p>
<button onclick="b()">開始</button>
<p id="dice2"></p>
<p>自訂骰面</p>
骰子面數:<br>
<input type="text"id="box1"><br>
<button onclick="c()">開始</button>
<p id="dice3"></p>
<p>機率判定</p>
機率:<br>
<input type="text"id="box2"><br>
<button onclick="d()">開始</button>
<p id="dice4"></p>
<script>
function a() {
var x = Math.floor((Math.random() * 6) + 1);
document.getElementById("dice1").innerHTML = x;
}
</script>
<script>
function b() {
var x = Math.floor((Math.random() * 10) + 1);
document.getElementById("dice2").innerHTML = x;
}
</script>
<script>
function c() {
x= document.getElementById("box1").value;
var y = Math.floor((Math.random() * x) + 1);
document.getElementById("dice3").innerHTML = y;
}
</script>
<script>
function d() {
x= document.getElementById("box2").value;
var y = Math.floor((Math.random() * 100) + 1);
if(y<x)
{document.getElementById("dice4").innerHTML = "失敗";}
if
(y>x){document.getElementById("dice4").innerHTML = "成功";}
}
</script>
</body>
</html>