-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
19 lines (17 loc) · 779 Bytes
/
index.js
File metadata and controls
19 lines (17 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var randomNumber1 = Math.floor(Math.random()*6) + 1;
var randomDiceImg1 = "dice" + randomNumber1 + ".png" ;
var randomDiceSrc1 = "images/" + randomDiceImg1 ;
var image1 = document.querySelectorAll("img")[0];
image1.setAttribute("src", randomDiceSrc1);
var randomNumber2 = Math.floor(Math.random()*6) + 1;
var randomDiceImg2 = "dice" + randomNumber2 + ".png";
var randomDiceSrc2 = "images/" + randomDiceImg2;
var image2 = document.querySelectorAll("img")[1];
image2.setAttribute("src", randomDiceSrc2);
if (randomNumber1>randomNumber2){
document.querySelector("h1").innerHTML="Play 1 wins!";
} else if (randomNumber1<randomNumber2){
document.querySelector("h1").innerHTML="Play 2 wins!";
} else {
document.querySelector("h1").innerHTML="Draw!";
}