-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (22 loc) · 955 Bytes
/
script.js
File metadata and controls
32 lines (22 loc) · 955 Bytes
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
var randomNumber1 = Math.floor(Math.random() * 6) + 1;
var randomNumber2 = Math.floor(Math.random() * 6) + 1;
var randomDice1 = "Dice " + randomNumber1 + ".png";
var randomDice2 = "Dice " + randomNumber2 + ".png";
var randomDiceSource1 = "images/" + randomDice1;
var randomDiceSource2 = "images/" + randomDice2;
var image1 = document.querySelectorAll("img")[0];
var image2 = document.querySelectorAll("img")[1];
var buttonPlay = document.getElementById("btnPlay");
var conditionNum = 0;
function playDice() {
image1.setAttribute("src", randomDiceSource1);
image2.setAttribute("src", randomDiceSource2);
if (randomNumber1 > randomNumber2) {
document.querySelector("h1").innerHTML = "🚩 Player 1 Win!";
} else if (randomNumber2 > randomNumber1) {
document.querySelector("h1").innerHTML = "Player 2 Win! 🚩";
} else {
document.querySelector("h1").innerHTML = "Draw!";
}
}
playDice();