-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
26 lines (23 loc) · 670 Bytes
/
script.js
File metadata and controls
26 lines (23 loc) · 670 Bytes
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
var cube = document.querySelector(".cube");
var rollBtn = document.querySelector(".rollBtn");
var currentClass = "";
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min);
//The maximum is exclusive and the minimum is inclusive
}
function rollDice() {
var randNum = getRandomInt(1, 7);
console.log(randNum);
var showClass = "show-" + randNum;
console.log(showClass);
if (currentClass) {
cube.classList.remove(currentClass);
}
cube.classList.add(showClass);
currentClass = showClass;
}
// set initial side
rollDice();
rollBtn.addEventListener("click", rollDice);