-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
51 lines (42 loc) · 1.39 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<html>
<head>
<title>Jogo de Dados</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Jogo de Dados</h1>
<div class="container">
<div class="dice-container">
<h2>Jogador</h2>
<p id="player-dice" class="dice-value">-</p>
<button id="roll-player-dice" onclick="rollPlayerDice()" disabled>Rolar</button>
</div>
<div class="dice-container">
<h2>Máquina</h2>
<p id="computer-dice" class="dice-value">-</p>
</div>
</div>
<h2 id="result"></h2>
<script>
function rollPlayerDice() {
var playerDice = Math.floor(Math.random() * 6) + 1;
var computerDice = Math.floor(Math.random() * 6) + 1;
document.getElementById('player-dice').textContent = playerDice;
document.getElementById('computer-dice').textContent = computerDice;
var resultElement = document.getElementById('result');
if (playerDice > computerDice) {
resultElement.textContent = 'Você ganhou!';
} else if (playerDice < computerDice) {
resultElement.textContent = 'A máquina ganhou!';
} else {
resultElement.textContent = 'Empate!';
}
}
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('roll-player-dice').addEventListener('click', rollPlayerDice);
document.getElementById('roll-player-dice').disabled = false;
});
</script>
</body>
</html>