-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathid.js
25 lines (22 loc) · 765 Bytes
/
id.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
var randomNumber1=Math.random();
randomNumber1*=6;
randomNumber1=Math.floor(randomNumber1)+1;
var diceNumber1="dice"+randomNumber1+".png";
var imageSource1="images/"+diceNumber1;
document.querySelectorAll("img")[0].setAttribute("src",imageSource1);
var randomNumber2=Math.random();
randomNumber2*=6;
randomNumber2=Math.floor(randomNumber2)+1;
var diceNumber2="dice"+randomNumber2+".png";
var imageSource2="images/"+diceNumber2;
document.querySelectorAll("img")[1].setAttribute("src",imageSource2);
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="It's a tie!!!";
}