-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
46 lines (32 loc) · 1.25 KB
/
test.js
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
// Player name
var player1 = "Player 1";
var player2 = "Player 2";
// Function to change the playe name
function editNames() {
tdnome1 = document.querySelector("#nome1");
tdnome2 = document.querySelector("#nome2");
tdnome1.textContent = nome1;
tdnome2.textContent = nome2;
player1 = prompt("Change Player1 name");
player2 = prompt("Change Player2 name");
nome1 = player1;
nome2 = player2;
tdnome1.textContent = nome1;
tdnome2.textContent = nome2;
}
// Function to roll the dice
function rollTheDice() {
setTimeout(function() {
var randomNumber1 = Math.floor(Math.random() * 6) + 1;
var randomNumber2 = Math.floor(Math.random() * 6) + 1;
document.querySelector(".img1").setAttribute("src", "images/dice" + randomNumber1 + ".png");
document.querySelector(".img2").setAttribute("src", "images/dice" + randomNumber2 + ".png");
if (randomNumber1 === randomNumber2) {
document.querySelector("h1").innerHTML = "Draw!";
} else if (randomNumber1 < randomNumber2) {
document.querySelector("h1").innerHTML = (player2 + " WINS!");
} else {
document.querySelector("h1").innerHTML = (player1 + " WINS!");
}
}, 25);
}