|  | 
| 1 |  | -const diceElement = document.getElementById("dice"); | 
| 2 |  | -const rollButton = document.getElementById("roll-button"); | 
| 3 |  | -const rollHistory = document.getElementById("roll-history"); | 
|  | 1 | +const buttonEl = document.getElementById("roll-button"); | 
|  | 2 | + | 
|  | 3 | +const diceEl = document.getElementById("dice"); | 
|  | 4 | + | 
|  | 5 | +const rollHistoryEl = document.getElementById("roll-history"); | 
|  | 6 | + | 
| 4 | 7 | let historyList = []; | 
| 5 | 8 | 
 | 
| 6 | 9 | function rollDice() { | 
| 7 | 10 |   const rollResult = Math.floor(Math.random() * 6) + 1; | 
| 8 | 11 |   const diceFace = getDiceFace(rollResult); | 
| 9 |  | -  diceElement.textContent = diceFace; | 
|  | 12 | +  diceEl.innerHTML = diceFace; | 
| 10 | 13 |   historyList.push(rollResult); | 
| 11 | 14 |   updateRollHistory(); | 
| 12 | 15 | } | 
| 13 | 16 | 
 | 
|  | 17 | +function updateRollHistory() { | 
|  | 18 | +  rollHistoryEl.innerHTML = ""; | 
|  | 19 | +  for (let i = 0; i < historyList.length; i++) { | 
|  | 20 | +    const listItem = document.createElement("li"); | 
|  | 21 | +    listItem.innerHTML = `Roll ${i + 1}: <span>${getDiceFace( | 
|  | 22 | +      historyList[i] | 
|  | 23 | +    )}</span>`; | 
|  | 24 | +    rollHistoryEl.appendChild(listItem); | 
|  | 25 | +  } | 
|  | 26 | +} | 
|  | 27 | + | 
| 14 | 28 | function getDiceFace(rollResult) { | 
| 15 | 29 |   switch (rollResult) { | 
| 16 | 30 |     case 1: | 
| 17 |  | -      return "⚀"; | 
|  | 31 | +      return "⚀"; | 
| 18 | 32 |     case 2: | 
| 19 |  | -      return "⚁"; | 
|  | 33 | +      return "⚁"; | 
| 20 | 34 |     case 3: | 
| 21 |  | -      return "⚂"; | 
|  | 35 | +      return "⚂"; | 
| 22 | 36 |     case 4: | 
| 23 |  | -      return "⚃"; | 
|  | 37 | +      return "⚃"; | 
| 24 | 38 |     case 5: | 
| 25 |  | -      return "⚄"; | 
|  | 39 | +      return "⚄"; | 
| 26 | 40 |     case 6: | 
| 27 |  | -      return "⚅"; | 
|  | 41 | +      return "⚅"; | 
| 28 | 42 |     default: | 
| 29 | 43 |       return ""; | 
| 30 | 44 |   } | 
| 31 | 45 | } | 
| 32 | 46 | 
 | 
| 33 |  | -function updateRollHistory() { | 
| 34 |  | -  rollHistory.innerHTML = ""; | 
| 35 |  | -  for (let i = 0; i < historyList.length; i++) { | 
| 36 |  | -    const listItem = document.createElement("li"); | 
| 37 |  | -    listItem.innerHTML = `Roll ${i + 1}: <span>${getDiceFace( | 
| 38 |  | -      historyList[i] | 
| 39 |  | -    )}</span>`; | 
| 40 |  | -    rollHistory.appendChild(listItem); | 
| 41 |  | -  } | 
| 42 |  | -} | 
| 43 |  | - | 
| 44 |  | -rollButton.addEventListener("click", () => { | 
| 45 |  | -  diceElement.classList.add("roll-animation"); | 
|  | 47 | +buttonEl.addEventListener("click", () => { | 
|  | 48 | +  diceEl.classList.add("roll-animation"); | 
| 46 | 49 |   setTimeout(() => { | 
| 47 |  | -    diceElement.classList.remove("roll-animation"); | 
|  | 50 | +    diceEl.classList.remove("roll-animation"); | 
| 48 | 51 |     rollDice(); | 
| 49 | 52 |   }, 1000); | 
| 50 | 53 | }); | 
0 commit comments