File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
project-9-dice-roll-simulator Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -3,12 +3,27 @@ const buttonEl = document.getElementById("roll-button");
3
3
4
4
const diceEl = document . getElementById ( "dice" ) ;
5
5
6
+ const rollHistoryEl = document . getElementById ( "roll-history" ) ;
7
+
8
+ let historyList = [ ] ;
9
+
6
10
function rollDice ( ) {
7
11
const rollResult = Math . floor ( Math . random ( ) * 6 ) + 1 ;
8
12
// console.log(rollResult);
9
13
const diceFace = getDiceFace ( rollResult ) ;
10
14
// console.log(diceFace);
11
15
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
+ }
12
27
}
13
28
14
29
function getDiceFace ( rollResult ) {
You can’t perform that action at this time.
0 commit comments