-
Notifications
You must be signed in to change notification settings - Fork 0
/
dicee.js
29 lines (18 loc) · 829 Bytes
/
dicee.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; //1-6
var randomDiceImage = "dice" + randomNumber1 + ".png"; //dice1.png - dice6.png
var randomImagesource = "Images/" + randomDiceImage; //Images/dice1.png - Images/dice6.png
var image1 = document.querySelectorAll("img")[0];
image1.setAttribute("src", randomImagesource);
var randomNumber2 = Math.floor(Math.random() * 6) + 1;
var randomImagesource2 = "Images/dice" + randomNumber2 + ".png";
document.querySelectorAll("img")[1].setAttribute("src", randomImagesource2);
//If player 1 wins
if (randomNumber1 > randomNumber2) {
document.querySelector("h1").innerHTML = "🚩 Play 1 Wins!";
}
else if (randomNumber2 > randomNumber1) {
document.querySelector("h1").innerHTML = "Player 2 Wins! 🚩";
}
else {
document.querySelector("h1").innerHTML = "Draw!";
}