-
Notifications
You must be signed in to change notification settings - Fork 0
/
dice.html
executable file
·66 lines (62 loc) · 2.18 KB
/
dice.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
60
61
62
63
64
65
66
<html>
<head>
<title>Dice Baseball</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
<script type="text/javascript">
function roll()
{
// Get random number
let random = Math.floor(Math.random() * 5001);
// Get roll container, status, and code
const container = document.getElementById('roll-container');
const status = document.getElementById('roll-status');
const code = document.getElementById('roll-code');
// Determine roll
if (random <= 889) {
status.innerHTML = 'Single';
} else if (random <= 1163) {
status.innerHTML = 'Double';
} else if (random <= 1191) {
status.innerHTML = 'Triple';
} else if (random <= 1340) {
status.innerHTML = 'Home Run';
} else if (random <= 1647) {
status.innerHTML = 'Walk';
} else if (random <= 1680) {
status.innerHTML = 'Hit by pitch';
} else if (random <= 1728) {
status.innerHTML = 'Out';
} else if (random <= 2585) {
status.innerHTML = 'Strikeout';
} else if (random <= 2691) {
status.innerHTML = 'Double play';
} else if (random <= 2728) {
status.innerHTML = 'Sacrifice fly';
} else {
status.innerHTML = 'Out';
}
// Set code
code.innerHTML = `Code ${random}`;
// Set timeout to invert container
setTimeout(() => {
container.style.backgroundColor = '#000';
container.style.color = '#fff';
}, 3000);
}
</script>
</head>
<body>
<div class="d-flex flex-column h-100">
<header class="text-center fs-1 mb-2">Dice Baseball</header>
<section class="align-items-center d-flex flex-fill">
<div id="roll-container" class="container-fluid text-center">
<div id="roll-status" class="fs-1 fw-bold"></div>
<div id="roll-code" class="fs-6"></div>
</div>
</section>
<footer class="mt-2 pb-2 text-center">
<button class="btn btn-lg btn-primary" onclick="roll(); return false;">Roll</button>
</footer>
</div>
</body>
</html>