-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (27 loc) · 1.37 KB
/
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// var randomNumber1 = Math.floor(Math.random()*6) + 1 ;
// var randomNumber2 = Math.floor(Math.random()*6) + 1;
// document.querySelector(".img1").setAttribute("src", "images/dice"+randomNumber1+".png");
// document.querySelector(".img2").setAttribute("src", "images/dice"+randomNumber2+".png");
// if(randomNumber1 > randomNumber2){
// document.querySelector("h1").textContent = "🚩Player 1 wins!";
// }else if(randomNumber1 < randomNumber2){
// document.querySelector("h1").textContent = "Player 2 wins! 🚩";
// }else if(randomNumber1 == randomNumber2){
// document.querySelector("h1").textContent = "Draw!";
// }
// Angela code
var randomNumber1 = Math.floor(Math.random() * 6 ) + 1;
var randomDiceImage = "dice" + randomNumber1 + ".png";
var randomImageSource = "images/" + randomDiceImage;
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(randomNumber1 > randomNumber2){
document.querySelector("h1").innerHTML = "🚩 Player 1 wins!";
} else if(randomNumber2 > randomNumber1){
document.querySelector("h1").innerHTML = "Player 2 wins! 🚩";
} else {
document.querySelector("hi").innerHTML = "Draw!";
}