-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
139 lines (106 loc) · 3.99 KB
/
Copy pathindex.js
File metadata and controls
139 lines (106 loc) · 3.99 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
"use strict";
const diceOne = document.querySelector(`.dice-one`);
const diceTwo = document.querySelector(`.dice-two`);
const diceThree = document.querySelector(`.dice-three`);
const diceFour = document.querySelector(`.dice-four`);
const scorePlayerOne = document.querySelector(`.score-player1`);
const scorePlayerTwo = document.querySelector(`.score-player2`);
const diceScorePlayerOne = document.querySelector(`.dice-score-player1`);
const diceScorePlayerTwo = document.querySelector(`.dice-score-player2`);
const buttonRollDicePlayerOne = document.querySelector(`.roll-dice-player1`);
const buttonRollDicePlayerTwo = document.querySelector(`.roll-dice-player2`);
const buttonPlayAgaing = document.querySelector(`.play-again`);
const buttonNewGame = document.querySelector(`.new-game`);
const dipsplayWinner = document.querySelector(`.winner`);
const playerOne = document.querySelector(`.player-one`);
const playerTwo = document.querySelector(`.player-two`);
let x = 0;
let y = 0;
let z = 0;
let q = 0;
let playing = true;
let whoPlays = true;
buttonRollDicePlayerOne.addEventListener(`click`, () =>{
setTimeout(() => {
if(playing === true && whoPlays === true){
diceOne.textContent = (Math.trunc(Math.random() * 6) + 1);
diceTwo.textContent = (Math.trunc(Math.random() * 6) + 1);
if(Number(diceOne.textContent) + Number(diceTwo.textContent) === 7){
x = 0;
diceScorePlayerOne.textContent = x;
}
else{
x += Number(diceOne.textContent) + Number(diceTwo.textContent);
diceScorePlayerOne.textContent = x;
if(x >= 30){
dipsplayWinner.textContent = `Player 1 Wins!`;
z++;
scorePlayerOne.textContent = z;
playing = false;
}
}
whoPlays = !whoPlays;
playerTwo.textContent = `✔`;
playerOne.textContent = ``;
}
}, 500);
});
buttonRollDicePlayerTwo.addEventListener(`click`, () =>{
setTimeout(() => {
if(playing === true && whoPlays === false){
diceThree.textContent = (Math.trunc(Math.random() * 6) + 1);
diceFour.textContent = (Math.trunc(Math.random() * 6) + 1);
if(Number(diceThree.textContent) + Number(diceFour.textContent) === 7){
y = 0;
diceScorePlayerTwo.textContent = y;
}
else{
y += Number(diceThree.textContent) + Number(diceFour.textContent);
diceScorePlayerTwo.textContent = y;
if(y >= 30){
dipsplayWinner.textContent = `Player 2 Wins!`;
q++;
scorePlayerTwo.textContent = q;
playing = false;
}
}
whoPlays = !whoPlays;
playerOne.textContent = `✔`;
playerTwo.textContent = ``;
}
}, 500);
});
buttonPlayAgaing.addEventListener(`click`, () =>{
x = 0;
y = 0;
diceScorePlayerOne.textContent = x;
diceScorePlayerTwo.textContent = y;
diceOne.textContent = `◆`;
diceTwo.textContent = `◆`;
diceThree.textContent = `◆`;
diceFour.textContent = `◆`;
dipsplayWinner.textContent = `Who Will Win?`;
playing = true;
whoPlays = true;
playerOne.textContent = `✔`;
playerTwo.textContent = ``;
});
buttonNewGame.addEventListener(`click`, () =>{
x = 0;
y = 0;
z = 0;
q = 0;
diceScorePlayerOne.textContent = x;
diceScorePlayerTwo.textContent = y;
scorePlayerOne.textContent = z;
scorePlayerTwo.textContent = q;
diceOne.textContent = `◆`;
diceTwo.textContent = `◆`;
diceThree.textContent = `◆`;
diceFour.textContent = `◆`;
dipsplayWinner.textContent = `Who Will Win?`;
playing = true;
whoPlays = true;
playerOne.textContent = `✔`;
playerTwo.textContent = ``;
});