Skip to content

Commit 5dd6128

Browse files
Update main.js
1 parent 1c7409d commit 5dd6128

File tree

1 file changed

+25
-1
lines changed
  • project-9-dice-roll-simulator

1 file changed

+25
-1
lines changed

project-9-dice-roll-simulator/main.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
1-
// ----------
21

32
const buttonEl = document.getElementById("roll-button");
43

54
const diceEl = document.getElementById("dice");
65

6+
function rollDice() {
7+
const rollResult = Math.floor(Math.random() * 6) + 1;
8+
// console.log(rollResult);
9+
const rollFace = getDiceFace(rollResult);
10+
console.log(rollFace);
11+
}
12+
13+
function getDiceFace(rollResult){
14+
switch(rollResult){
15+
case 1:
16+
return "&#9856";
17+
case 2:
18+
return "&#9857";
19+
case 3:
20+
return "&#9858";
21+
case 4:
22+
return "&#9859";
23+
case 5:
24+
return "&#9860";
25+
case 6:
26+
return "&#9861";
27+
}
28+
}
29+
730
buttonEl.addEventListener("click", ()=> {
831
// console.log("Clicked!");
932
diceEl.classList.add("roll-animation");
1033
setTimeout( () => {
1134
diceEl.classList.remove("roll-animation");
35+
rollDice();
1236
}, 1000);
1337
})

0 commit comments

Comments
 (0)