Skip to content

Commit 8abf96f

Browse files
Merge pull request #820 from nagurumavis/patch-4
Create app2.js
2 parents 65d76b1 + b166741 commit 8abf96f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

app2.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Function to generate a random number between 1 and 6
2+
function rollDice() {
3+
return Math.floor(Math.random() * 6) + 1;
4+
}
5+
6+
// Update the dice face and result based on the roll
7+
function updateGame(diceValue) {
8+
const diceDiv = document.querySelector('.dice');
9+
const resultDiv = document.querySelector('.result');
10+
11+
// Display different dice faces based on the roll value
12+
const diceFaces = ['⚀', '⚁', '⚂', '⚃', '⚄', '⚅'];
13+
diceDiv.textContent = diceFaces[diceValue - 1];
14+
15+
// Display the result
16+
resultDiv.textContent = You rolled a ${diceValue}!;
17+
}
18+
19+
// Add event listener to the roll button
20+
document.getElementById('rollButton').addEventListener('click', () => {
21+
const diceValue = rollDice();
22+
updateGame(diceValue);
23+
});

0 commit comments

Comments
 (0)