-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (33 loc) · 1021 Bytes
/
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
window.onload = function() {
var reloading = sessionStorage.getItem("reloading");
if (reloading) {
sessionStorage.removeItem("reloading");
fun1();
}
}
function reloadP()
{
sessionStorage.setItem("reloading", "true");
document.location.reload();
}
function fun1(){
var randomNumber1 = Math.random();
randomNumber1 = Math.floor(randomNumber1*6) + 1;
var randomNumber2 = Math.random();
randomNumber2 = Math.floor(randomNumber2*6) + 1;
var name1 = "dice"+randomNumber1+".png";
var name2 = "dice"+randomNumber2+".png";
document.querySelector(".Player1").setAttribute("src",name1);
document.querySelector(".Player2").setAttribute("src",name2);
if(randomNumber1>randomNumber2)
{
document.querySelector("h1").innerHTML="Player 1 Wins 🎉";
}
else if(randomNumber1<randomNumber2)
{
document.querySelector("h1").innerHTML="Player 2 Wins 🎉";
}
else{
document.querySelector("h1").innerHTML="Draw!!";
}
}