-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
29 lines (25 loc) · 1.12 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
var randomNumber1 = Math.floor(Math.random() * 6 + 1);
var randomNumber2 = Math.floor(Math.random() * 6 + 1);
var imageSource1 = "images/dice" + randomNumber1 + ".png";
var imageSource2 = "images/dice" + randomNumber2 + ".png";
var image1 = document.querySelectorAll("img")[0];
// var image1 = document.querySelector(".img1"); another way to select the image1
var image2 = document.querySelectorAll("img")[1];
image1.setAttribute("src",imageSource1);
image2.setAttribute("src",imageSource2);
var refreshButton = document.querySelector(".btn");
refreshButton.addEventListener("click",function(){
var heading = document.querySelector("h1").innerHTML = "processing..."
this.classList.add("invisible");
setTimeout(() => {
window.location.reload();
}, 1000);
})
if(randomNumber1>randomNumber2){
document.querySelector("h1").innerHTML = "Player 1 wins 🚩";
}else if(randomNumber2 > randomNumber1){
document.querySelector("h1").innerHTML = "🚩 Won by player 2";
}else{
document.querySelector("h1").innerHTML = "Draw ! 😪" ;
}
// on pressing r or s pagee should reload