-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroller.html
57 lines (51 loc) · 1.24 KB
/
roller.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
<html>
<head>
<title>Dice Roller</title>
<style>
button {
padding: 10px;
font-size: 120%;
cursor: pointer;
}
section {
margin: 0;
padding: 100px;
}
label {
display: block;
margin: 15px;
}
td,
th {
text-align: center;
padding: 25px;
}
</style>
</head>
<body>
<section>
<form>
<h1>Roll Dice</h1>
<p>Problem: How do we re-create a random dice roll of a 20-sided dice?</p>
<table>
<tr><th>Math.random (Random Number Between 0 and 1)</th><th></th><th>Unrounded Result</th><th>Math.floor (Rounded down)</th><th>Math.ceil (Rounded up)</th></tr>
<tr><td id="mathrandom">00</td><td>x 20</td><td id="mathresult">00</td><td id="mathfloor">00</td><td id="mathceil">00</td></tr>
</table>
<button id='roller' onclick='rollDice()' type='button'>Roll a d20!</button>
</form>
</section>
<script>
function rollDice() {
//alert("CHEESE");
var random = Math.random();
document.getElementById("mathrandom").innerHTML = random;
var result = random*20;
document.getElementById("mathresult").innerHTML = result;
var down = Math.floor(result);
document.getElementById("mathfloor").innerHTML = down;
var up = Math.ceil(result);
document.getElementById("mathceil").innerHTML = up;
}
</script>
</body>
</html>