Skip to content

Commit 62e67fc

Browse files
Created a Dice Rolling Simulator
1 parent 837d8a8 commit 62e67fc

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed
54.4 KB
Binary file not shown.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
<style>
8+
.dice {
9+
text-align: center;
10+
margin: auto;
11+
}
12+
.main {
13+
max-width: 400px;
14+
}
15+
#rolling-dice {
16+
width: 200px;
17+
}
18+
#rolling-dice video {
19+
width: 200px;
20+
}
21+
#button {
22+
width: 200px;
23+
cursor: pointer;
24+
}
25+
#output-text {
26+
width: 200px;
27+
color: red;
28+
}
29+
footer {
30+
position: fixed;
31+
bottom: 0;
32+
}
33+
</style>
34+
35+
</head>
36+
<body>
37+
<div>
38+
<h1>Dice Rolling Simulator</h1>
39+
<div class="dice">
40+
41+
</div>
42+
<div class="main">
43+
<input type="button" value="Roll" id="button">
44+
<br>
45+
<div id="rolling-dice">
46+
<video
47+
src="./Dice.mp4" loop
48+
type="video/mp4" muted autoplay
49+
></video>
50+
</div>
51+
52+
<h2>Output: <span id="output-text"></span></h2>
53+
</div>
54+
55+
</div>
56+
57+
<footer>Developed by Contributor Kaustubh</footer>
58+
59+
<script src="script.js"></script>
60+
</body>
61+
62+
</html>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// input element displaying button is referenced in the 'button' variable.
2+
const button = document.querySelector('#button');
3+
// video element displaying animation is referenced in the 'animation' variable.
4+
const animation = document.getElementById('rolling-dice');
5+
// span element displaying the output is referenced in the 'output' variable.
6+
const output = document.getElementById('output-text');
7+
8+
// function 'getRandomIntegerInclusive' generates a number between 1 to 6.
9+
function getRandomIntegerInclusive(min, max) {
10+
min = Math.ceil(min);
11+
max = Math.floor(max);
12+
return Math.floor(Math.random() * (max - min + 1)) + min;
13+
}
14+
15+
// When 'Roll' button is clicked then below action is carried out.
16+
button.addEventListener('click', function() {
17+
// video containing rolling-dice animation is hidden.
18+
animation.style.visibility = 'hidden';
19+
// adding a slight delay for effective visual effect.
20+
setTimeout(() => {
21+
// we will generate a random number by calling 'getRandomIntegerInclusive' function.
22+
let randomInteger = getRandomIntegerInclusive(1, 6);
23+
console.log(randomInteger);
24+
// Now, displaying the output number in the span element
25+
output.textContent = randomInteger;
26+
27+
// Now, displaying the dice rolling animation again.
28+
if(output.textContent != "") {
29+
animation.style.visibility = 'visible';
30+
}
31+
}, 500);
32+
33+
});

0 commit comments

Comments
 (0)