-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (52 loc) · 1.71 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
59
60
61
// For 1st Dicee
var n = Math.random()*6;
var randomNumber1 = Math.floor(n) + 1;
if (randomNumber1 === 1){
document.querySelector(".img1").setAttribute("src", "images/dice1.png");
}
else if (randomNumber1 === 2){
document.querySelector(".img1").setAttribute("src", "images/dice2.png");
}
else if (randomNumber1 === 3){
document.querySelector(".img1").setAttribute("src", "images/dice3.png");
}
else if (randomNumber1 === 4){
document.querySelector(".img1").setAttribute("src", "images/dice4.png");
}
else if (randomNumber1 === 5){
document.querySelector(".img1").setAttribute("src", "images/dice5.png");
}
else {
document.querySelector(".img1").setAttribute("src", "images/dice6.png");
}
// For 2nd Dicee
var a = Math.random()*6;
var randomNumber2 = Math.floor(a) + 1;
if (randomNumber2 === 1){
document.querySelector(".img2").setAttribute("src", "images/dice1.png");
}
else if (randomNumber2 === 2){
document.querySelector(".img2").setAttribute("src", "images/dice2.png");
}
else if (randomNumber2 === 3){
document.querySelector(".img2").setAttribute("src", "images/dice3.png");
}
else if (randomNumber2 === 4){
document.querySelector(".img2").setAttribute("src", "images/dice4.png");
}
else if (randomNumber2 === 5){
document.querySelector(".img2").setAttribute("src", "images/dice5.png");
}
else {
document.querySelector(".img2").setAttribute("src", "images/dice6.png");
}
// For Displaying Result
if (randomNumber1 > randomNumber2){
document.querySelector("h2").textContent = "🚩 Player 1 Wins! ";
}
else if (randomNumber1 < randomNumber2){
document.querySelector("h2").textContent = "Player 2 Wins! 🚩";
}
else {
document.querySelector("h2").textContent = "Draw! 😑";
}