-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
21 lines (19 loc) · 875 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
var randomNumber1 = Math.floor(Math.random()*6)+1; //1 - 6
var randomDiceImage = "dice" + randomNumber1 + ".png"; // dice1.png - dice6.png
var randomImageSource = "Images/" + randomDiceImage; //Images/dice1.png - Imagaes/dice2.png
var image1 = document.querySelectorAll("img")[0];
image1.setAttribute("src",randomImageSource);
var randomNumber2 = Math.floor(Math.random()*6)+1;
var randomDiceImage = "dice" + randomNumber2 + ".png";
var randomImageSource = "Images/" + randomDiceImage;
var image2 = document.querySelectorAll("img")[1];
image2.setAttribute("src", randomImageSource);
if(randomNumber1>randomNumber2){
document.querySelector("h1").innerHTML="Player1 wins!🤩";
}
else if(randomNumber1<randomNumber2){
document.querySelector("h1").innerHTML="Player2 wins!😋";
}
else{
document.querySelector("h1").innerHTML="Draw!😄";
}