-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (28 loc) · 883 Bytes
/
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
var dice = ["images/dice-one.png", "images/dice-two.png", "images/dice-three.png", "images/dice-four.png", "images/dice-five.png", "images/dice-six.png"]
var dice1 = document.getElementById("dice1");
var dice2 = document.getElementById("dice2");
var result = document.getElementById("result")
function rollDice() {
let number = Math.floor(Math.random() * 5) + 1;
return number;
}
function getDice(number) {
return dice[number];
}
function game() {
var player1 = rollDice();
var player2 = rollDice();
dice1.setAttribute("src", getDice(player1));
dice2.setAttribute("src", getDice(player2));
let score;
if (player1 > player2) {
score = "Player 1 wins!";
}
else if (player1 < player2) {
score = "Player 2 wins!";
}
else {
score = "It's a tie! Play again.";
}
result.innerHTML = score;
}