-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
27 lines (19 loc) · 891 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
let randomNumber1 =Math.random();
randomNumber1 = Math.floor(randomNumber1 * 6)+ 1;
let randomDiceImage = "dice" + randomNumber1+ ".png" //dice 1-6 .png;
let randomImagesSource = "images/" + randomDiceImage;
let image1 = document.querySelectorAll("img")[0];
image1.setAttribute("src", randomImagesSource);
// random number 2 generator
let randomNumber2 = Math.random();
randomNumber2 = Math.floor(randomNumber2 * 6) +1 ;
let randomImageSource2 = "images/dice" + randomNumber2 + ".png" ;
document.querySelectorAll("img")[1].setAttribute("src",randomImageSource2);
//player 1 wins
if (randomNumber1 > randomNumber2) {
document.querySelector("h1").innerHTML = "player 1 wins!😎";
}else if (randomNumber2 > randomNumber1) {
document.querySelector("h1").innerHTML = "player 2 wins!😎";
}else {
document.querySelector("h1").innerHTML = "Draw!";
}