-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
48 lines (36 loc) · 1.23 KB
/
index.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
47
48
$(".start").click(function() {
rollDice();
setTimeout(rollDice, 500);
setTimeout(rollDice, 500);
setTimeout(rollDice, 500);
setTimeout(rollDice, 500);
setTimeout(rollDice, 500);
setTimeout(rollDice, 500);
setTimeout(rollDice, 500);
setTimeout(rollDice, 500);
setTimeout(rollDice, 500);
setTimeout(rollDice, 500);
setTimeout(rollDice, 500);
setTimeout(rollDice, 500);
setTimeout(rollDice, 500);
setTimeout(winnerDecision, 500);
});
function rollDice() {
var randomNumber1 = Math.floor(Math.random() * 6) + 1;
$(".img1").attr("src", "images/dice" + randomNumber1 + ".png");
var randomNumber2 = Math.floor(Math.random() * 6) + 1;
$(".img2").attr("src", "images/dice" + randomNumber2 + ".png");
}
function winnerDecision() {
var randomNumber1 = Math.floor(Math.random() * 6) + 1;
$(".img1").attr("src", "images/dice" + randomNumber1 + ".png");
var randomNumber2 = Math.floor(Math.random() * 6) + 1;
$(".img2").attr("src", "images/dice" + randomNumber2 + ".png");
if (randomNumber1 > randomNumber2) {
$("h1").text("Player 1 wins.");
} else if (randomNumber1 < randomNumber2) {
$("h1").text("Player 2 wins.");
} else if (randomNumber1 === randomNumber2) {
$("h1").text("Draw.");
}
}