-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (52 loc) · 2.08 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
49
50
51
52
53
54
55
56
57
58
function rollDice() {
var p1 = document.querySelector(".p-1 i")
var p2 = document.querySelector(".p-2 i")
var btn = document.querySelector(".btn")
var randomP1 = Math.floor((Math.random() * 6)) + 1
if (randomP1 === 1) {
p1.removeAttribute("class", "fas fa-dice-one")
p1.setAttribute("class", "fas fa-dice-one")
} else if (randomP1 === 2) {
p1.removeAttribute("class", "fas fa-dice-one")
p1.setAttribute("class", "fas fa-dice-two")
} else if (randomP1 === 3) {
p1.removeAttribute("class", "fas fa-dice-one")
p1.setAttribute("class", "fas fa-dice-three")
} else if (randomP1 === 4) {
p1.removeAttribute("class", "fas fa-dice-one")
p1.setAttribute("class", "fas fa-dice-four")
} else if (randomP1 === 5) {
p1.removeAttribute("class", "fas fa-dice-one")
p1.setAttribute("class", "fas fa-dice-five")
} else if (randomP1 === 6) {
p1.removeAttribute("class", "fas fa-dice-one")
p1.setAttribute("class", "fas fa-dice-six")
}
var randomP2 = Math.floor((Math.random() * 6)) + 1
if (randomP2 === 1) {
p2.removeAttribute("class", "fas fa-dice-six")
p2.setAttribute("class", "fas fa-dice-one")
} else if (randomP2 === 2) {
p2.removeAttribute("class", "fas fa-dice-six")
p2.setAttribute("class", "fas fa-dice-two")
} else if (randomP2 === 3) {
p2.removeAttribute("class", "fas fa-dice-six")
p2.setAttribute("class", "fas fa-dice-three")
} else if (randomP2 === 4) {
p2.removeAttribute("class", "fas fa-dice-six")
p2.setAttribute("class", "fas fa-dice-four")
} else if (randomP2 === 5) {
p2.removeAttribute("class", "fas fa-dice-six")
p2.setAttribute("class", "fas fa-dice-five")
} else if (randomP2 === 6) {
p2.removeAttribute("class", "fas fa-dice-six")
p2.setAttribute("class", "fas fa-dice-six")
}
if (randomP1 > randomP2) {
btn.innerHTML = "<h1><i class='fas fa-flag'></i> Player 1 Won!</h1>"
} else if (randomP1 < randomP2) {
btn.innerHTML = "<h1><i class='fas fa-flag'></i> Player 2 Won!</h1>"
} else if (randomP1 === randomP2) {
btn.innerHTML = "<h1>You both Lost!</h1>"
}
}