-
Notifications
You must be signed in to change notification settings - Fork 0
/
dice.js
25 lines (21 loc) · 870 Bytes
/
dice.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
function changeDice ()
{
var diceNumber = ["images/dice1.png","images/dice2.png","images/dice3.png","images/dice4.png","images/dice5.png","images/dice6.png"];
var pickRandomDice1 = diceNumber[ Math.round( Math.random()*5 ) ];
var pickRandomDice2 = diceNumber[ Math.round( Math.random()*5 ) ];
document.querySelector(".img1").setAttribute("src", pickRandomDice1 );
document.querySelector(".img2").setAttribute("src", pickRandomDice2 );
if ( pickRandomDice1 > pickRandomDice2 )
{
document.querySelector("h1").textContent = "🎈 Player 1 wins";
}
else if ( pickRandomDice1 === pickRandomDice2 )
{
document.querySelector("h1").textContent = "Draw";
}
else
{
document.querySelector("h1").textContent = "Player 2 wins 🎈";
}
}
document.getElementById("changeDice").onclick = function() { changeDice() };