-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
104 lines (99 loc) · 5.44 KB
/
script.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Player name
var player1 = "Player 1";
var player2 = "Player 2";
var player3 = "Player 3";
// 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;
var randomNumber3 = Math.floor(Math.random() * 6) + 1;
document.getElementById('member-1').innerText = randomNumber1;
document.getElementById('member-2').innerText = randomNumber2;
document.getElementById('member-3').innerText = randomNumber3;
if (randomNumber1 == randomNumber2 && randomNumber1 > randomNumber3) {
document.querySelector("#winner").innerHTML = (player1 + " and " + player2 + " Draw!");
document.getElementById('member-1').style.color = "blue";
document.getElementById('member-2').style.color = "blue";
document.getElementById('member-3').style.color = "red";
if (randomNumber1 == randomNumber2 && randomNumber1 < randomNumber3) {
document.querySelector("#winner").innerHTML = (player1 + " and " + player2 + " Draw!");
document.getElementById('member-1').style.color = "blue";
document.getElementById('member-2').style.color = "blue";
document.getElementById('member-3').style.color = "green";
}
}
else if (randomNumber2 == randomNumber3 && randomNumber2 > randomNumber1) {
document.querySelector("#winner").innerHTML = (player2 + " and " + player3 + " Draw!");
document.getElementById('member-2').style.color = "blue";
document.getElementById('member-3').style.color = "blue";
document.getElementById('member-1').style.color = "red";
if (randomNumber2 == randomNumber3 && randomNumber2 < randomNumber1) {
document.querySelector("#winner").innerHTML = (player2 + " and " + player3 + " Draw!");
document.getElementById('member-2').style.color = "blue";
document.getElementById('member-3').style.color = "blue";
document.getElementById('member-1').style.color = "green";
}
}
else if (randomNumber3 == randomNumber1 && randomNumber3 > randomNumber2) {
document.querySelector("#winner").innerHTML = (player1 + " and " + player3 + " Draw!");
document.getElementById('member-1').style.color = "blue";
document.getElementById('member-3').style.color = "blue";
document.getElementById('member-2').style.color = "red";
if (randomNumber3 == randomNumber1 && randomNumber3 < randomNumber2) {
document.querySelector("#winner").innerHTML = (player2 + " and " + player3 + " Draw!");
document.getElementById('member-1').style.color = "blue";
document.getElementById('member-3').style.color = "blue";
document.getElementById('member-2').style.color = "green";
}
}
else if (randomNumber1 > randomNumber2 && randomNumber1 > randomNumber3) {
document.querySelector("#winner").innerHTML = (player1 + " WINS!");
document.getElementById('member-1').style.color = "green";
if (randomNumber2 > randomNumber3) {
document.getElementById('member-2').style.color = "yellow";
document.getElementById('member-3').style.color = "red";
}
else if (randomNumber3 > randomNumber2) {
document.getElementById('member-3').style.color = "yellow";
document.getElementById('member-2').style.color = "red";
}
else {
document.getElementById('member-2').style.color = "blue";
document.getElementById('member-3').style.color = "blue";
}
}
else if (randomNumber2 > randomNumber1 && randomNumber2 > randomNumber3) {
document.querySelector("#winner").innerHTML = (player2 + " WINS!");
document.getElementById('member-2').style.color = "green";
if (randomNumber1 > randomNumber3) {
document.getElementById('member-1').style.color = "yellow";
document.getElementById('member-3').style.color = "red";
}
else if (randomNumber3 > randomNumber1) {
document.getElementById('member-3').style.color = "yellow";
document.getElementById('member-1').style.color = "red";
}
else {
document.getElementById('member-1').style.color = "blue";
document.getElementById('member-3').style.color = "blue";
}
}
else {
document.querySelector("#winner").innerHTML = (player3 + " WINS!");
document.getElementById('member-3').style.color = "green";
if (randomNumber1 > randomNumber2) {
document.getElementById('member-1').style.color = "yellow";
document.getElementById('member-2').style.color = "red";
}
else if (randomNumber2 > randomNumber1) {
document.getElementById('member-2').style.color = "yellow";
document.getElementById('member-1').style.color = "red";
}
else {
document.getElementById('member-1').style.color = "blue";
document.getElementById('member-2').style.color = "blue";
}
}
}, 1000);
}