-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
38 lines (36 loc) · 1.05 KB
/
Copy pathscript.js
File metadata and controls
38 lines (36 loc) · 1.05 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
const button = document.getElementById('roll');
const dice = document.getElementById('dice');
const resultsList = document.getElementById('results');
let history = [];
function rollDice(){
const roll=Math.floor(Math.random()*6)+1;
history.push(roll);
dice.innerHTML=getDiceFace(roll);
updateResults();
}
function updateResults(){
resultsList.innerHTML="";
history.forEach((roll,index)=>{
const li=document.createElement("li");
li.innerHTML = `Roll ${index+1}: ${roll} <span>${getDiceFace(roll)}</span>`; // <-- FIXED
resultsList.appendChild(li);
});
}
function getDiceFace(rollResult) {
switch (rollResult) {
case 1: return "⚀";
case 2: return "⚁";
case 3: return "⚂";
case 4: return "⚃";
case 5: return "⚄";
case 6: return "⚅";
default: return "";
}
}
button.addEventListener("click",()=>{
dice.classList.add("roll");
setTimeout(()=>{
rollDice();
dice.classList.remove("roll");
},500);
});