-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
23 lines (22 loc) · 1.04 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
function play() {
var diceNo1 = Math.floor(Math.random() * 6) + 1;
var diceNo2 = Math.floor(Math.random() * 6) + 1;
alert(diceNo1);
alert(diceNo2);
document
.getElementById("img1")
.setAttribute("src", "./images/dice"+diceNo1+".png");
document
.getElementById("img2")
.setAttribute("src", "./images/dice"+diceNo2+".png");
if(diceNo1 > diceNo2){
document.getElementById("result").innerHTML = "Player 1 Wins <img id='resultImg' src='' class='resultImg'/>";
document.getElementById("resultImg").setAttribute("src","./images/red-flag.png");
}else if(diceNo1 < diceNo2){
document.getElementById("result").innerHTML = "Player 2 Wins <img id='resultImg' src='' class='resultImg'/>"
document.getElementById("resultImg").setAttribute("src","./images/red-flag.png");
}else if(diceNo1 === diceNo2){
document.getElementById("result").innerHTML = "Draw! <img id='resultImg' src='' class='resultImg'/>";
document.getElementById("resultImg").setAttribute("src","./images/whistle.png");
}
}