Skip to content

Commit 2cc50d3

Browse files
authoredJul 4, 2024··
Update main.js
1 parent 331c0d4 commit 2cc50d3

File tree

1 file changed

+15
-0
lines changed
  • project-9-dice-roll-simulator

1 file changed

+15
-0
lines changed
 

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,27 @@ const buttonEl = document.getElementById("roll-button");
33

44
const diceEl = document.getElementById("dice");
55

6+
const rollHistoryEl = document.getElementById("roll-history");
7+
8+
let historyList = [];
9+
610
function rollDice() {
711
const rollResult = Math.floor(Math.random() * 6) + 1;
812
// console.log(rollResult);
913
const diceFace = getDiceFace(rollResult);
1014
// console.log(diceFace);
1115
diceEl.innerHTML = diceFace;
16+
historyList.push(rollResult);
17+
updateRollHistory();
18+
}
19+
20+
function updateRollHistory(){
21+
rollHistoryEl.innerHTML = "";
22+
for (let i = 0; i < historyList.length; i++) {
23+
const listItem = document.createElement("li");
24+
listItem.innerHTML = `Roll ${i + 1}: <span>${getDiceFace(historyList[i])}</span>`;
25+
rollHistoryEl.appendChild(listItem);
26+
}
1227
}
1328

1429
function getDiceFace(rollResult){

0 commit comments

Comments
 (0)
Please sign in to comment.