-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrolldice.html
More file actions
108 lines (98 loc) · 2.58 KB
/
rolldice.html
File metadata and controls
108 lines (98 loc) · 2.58 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
*,
*::after,
*::before {
padding: 0;
margin: 0;
box-sizing: border-box;
}
html {
color-scheme: light dark;
}
#container {
font-family: Arial, Helvetica, sans-serif;
text-align: center;
font-size: 2rem;
font-weight: bold;
}
button {
font-size: 1.5rem;
padding: 10px 15px;
border-radius: 10px;
border: none;
cursor: pointer;
color:white;
background: black;
transition: 200ms ease-in-out;
}
button:hover {
background: white;
transform: scale(0.9);
color:black;
}
button:active {
background: white;
transform: scale(0.9);
color:black;
}
input {
font-size: 2rem;
width: 150px;
text-align: center;
font-weight: bold;
}
#diceResult{
color:white;
margin: 25px;
}
#diceImages img{
width: 150px;
height: 150px;
margin: 5px;
}
p{
color:White;
font-size: 2rem;
}
</style>
</head>
<body>
<div id="container">
<h1>Dice Roller</h1>
<label># of Dice</label>
<input type="number" id="numofdice" value="1" min="1" />
<button onclick="rollDice()">Roll Dice</button>
<div id="diceResult"></div>
<div id="diceImages"></div>
</div>
<script>
function rollDice() {
const numofdice= document.getElementById("numofdice").value,
diceImages= document.getElementById("diceImages"),
diceResult= document.getElementById("diceResult"),
values = [],
images=[];
for(let i = 0 ; i<numofdice;i++){
const value= Math.floor(Math.random()*6)+1;
values.push(value);
if(numofdice<=6){
images.push(`<img src="images/dice/dice${value}.svg" alt="Dice ${value}"></img>`);
}
else{
let parares= document.createElement('p')
diceResult.appendChild(parares)
parares.textContent = "Can only Roll upto six."
}
}
diceResult.textContent = `dice: ${values.join(',')}`;
diceImages.innerHTML =images.join("");
}
</script>
</body>
</html>