File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed
project-9-dice-roll-simulator Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change 1
- // ----------
2
1
3
2
const buttonEl = document . getElementById ( "roll-button" ) ;
4
3
5
4
const diceEl = document . getElementById ( "dice" ) ;
6
5
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 "⚀" ;
17
+ case 2 :
18
+ return "⚁" ;
19
+ case 3 :
20
+ return "⚂" ;
21
+ case 4 :
22
+ return "⚃" ;
23
+ case 5 :
24
+ return "⚄" ;
25
+ case 6 :
26
+ return "⚅" ;
27
+ }
28
+ }
29
+
7
30
buttonEl . addEventListener ( "click" , ( ) => {
8
31
// console.log("Clicked!");
9
32
diceEl . classList . add ( "roll-animation" ) ;
10
33
setTimeout ( ( ) => {
11
34
diceEl . classList . remove ( "roll-animation" ) ;
35
+ rollDice ( ) ;
12
36
} , 1000 ) ;
13
37
} )
You can’t perform that action at this time.
0 commit comments