-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
27 lines (23 loc) · 1.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
/*var randomNumber1 = Math.floor(Math.random() * 6)+1;
var randomNumber2 = Math.floor(Math.random() * 6)+1;
var ransomdice1 ="images/dice"+randomNumber1+".png";
var ransomdice2 ="images/dice"+randomNumber2+".png";
//document.querySelector(".example").style.backgroundColor = "red";
*/
function myFunction() {
var randomNumber1 = Math.floor(Math.random() * 6) + 1;
var randomNumber2 = Math.floor(Math.random() * 6) + 1;
var ransomdice1 = "images/dice" + randomNumber1 + ".png";
var ransomdice2 = "images/dice" + randomNumber2 + ".png";
document.querySelectorAll("img")[0].setAttribute("src", ransomdice1);
document.querySelectorAll("img")[1].setAttribute("src", ransomdice2);
if (randomNumber1 > randomNumber2) {
document.querySelector("h1").innerHTML = "Player 1 wins!!";
} else if (randomNumber1 === randomNumber2) {
document.querySelector("h1").innerHTML = "Its a tiw";
} else {
document.querySelector("h1").innerHTML = "Player 2 wins!!";
}
document.querySelector("button").innerHTML = "Play Again!!";
//document.location.reload();
}