-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
22 lines (17 loc) · 710 Bytes
/
Copy pathindex.js
File metadata and controls
22 lines (17 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
let randomNumber1 = Math.floor(Math.random() * 6) +1;
let randomNumber2 = Math.floor(Math.random() * 6) +1;
let randomDiceImage1 = "/images/dice" + randomNumber1 + ".png";
let randomDiceImage2 = "/images/dice" + randomNumber2 + ".png";
let image1= document.querySelectorAll("img")[0];
let image2= document.querySelectorAll("img")[1];
image1.setAttribute("src",randomDiceImage1);
image2.setAttribute("src",randomDiceImage2);
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!";
}