-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
186 lines (161 loc) · 5.48 KB
/
app.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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
const player1 = document.querySelector('#player-one');
const player2 = document.querySelector('#player-two');
const reset = document.querySelector('#reset');
const score1 = document.querySelector('.score1');
const score2 = document.querySelector('.score2');
const select = document.querySelector('select');
let games = select.value;
let num1 = 0;
let num2 = 0;
let win = 2;
const win5 = 3;
const win7 = 4;
function resetButton() {
score1.innerText = 0;
score2.innerText = 0;
num1 = 0;
num2 = 0;
player1.disabled = false;
player2.disabled = false;
score1.classList.remove('win-green');
score1.classList.remove('lose-red');
score2.classList.remove('win-green');
score2.classList.remove('lose-red');
//select.value = "3"
}
select.addEventListener('change', function(e){
//can use "this" in this situation instead of line below ==> this.value instead of e.target.value
games = e.target.value;
if (games ==="5"){
win = win5;
}
else if(games ==="7"){
win = win7;
}
else{win = 2}
console.log(`changed to ${games}`)
resetButton();
})
player1.addEventListener('click', function(e) {
num1++;
score1.innerText = num1;
if (num1 === win){
console.log('win');
player1.disabled = true;
player2.disabled = true;
score1.classList.toggle('win-green'); //could try bulma color in here instead ==> score1.classList.add('has-text-success')
score2.classList.toggle('lose-red'); // score2.classList.add('has-text-danger')
}
})
player2.addEventListener('click', function(e) {
num2++;
score2.innerText = num2;
if (num2 === win){
console.log('win');
player1.disabled = true;
player2.disabled = true;
score1.classList.toggle('lose-red');
score2.classList.toggle('win-green');
}
})
// if (games === "3"){
// num1=0;
// num2=0;
// player1.addEventListener('click', function(e) {
// num1++;
// score1.innerText = num1;
// if (num1 === win){
// console.log('win');
// player1.disabled = true;
// player2.disabled = true;
// score1.classList.toggle('win-green');
// score2.classList.toggle('lose-red');
// }
// })
// player2.addEventListener('click', function(e) {
// num2++;
// score2.innerText = num2;
// if (num2 === win){
// console.log('win');
// player1.disabled = true;
// player2.disabled = true;
// score1.classList.toggle('lose-red');
// score2.classList.toggle('win-green');
// }
// })
// }
// // for 5 games
// else if (games === "5"){
// num1=0;
// num2=0;
// player1.addEventListener('click', function(e) {
// num1++;
// score1.innerText = num1;
// if (num1 === win5){
// console.log('win');
// player1.disabled = true;
// player2.disabled = true;
// score1.classList.toggle('win-green');
// score2.classList.toggle('lose-red');
// }
// })
// player2.addEventListener('click', function(e) {
// num2++;
// score2.innerText = num2;
// if (num2 === win5){
// console.log('win');
// player1.disabled = true;
// player2.disabled = true;
// score1.classList.toggle('lose-red');
// score2.classList.toggle('win-green');
// }
// })
// }
// else if (games === "7"){
// num1=0;
// num2=0;
// player1.addEventListener('click', function(e) {
// num1++;
// score1.innerText = num1;
// if (num1 === win7){
// console.log('win');
// player1.disabled = true;
// player2.disabled = true;
// score1.classList.toggle('win-green');
// score2.classList.toggle('lose-red');
// }
// })
// player2.addEventListener('click', function(e) {
// num2++;
// score2.innerText = num2;
// if (num2 === win7){
// console.log('win');
// player1.disabled = true;
// player2.disabled = true;
// score1.classList.toggle('lose-red');
// score2.classList.toggle('win-green');
// }
// })
// }
reset.addEventListener('click', resetButton)
// player1.addEventListener('click', function(e) {
// num1++;
// score1.innerText = num1;
// })
// player2.addEventListener('click', function(e) {
// num2++;
// score2.innerText = num2;
// })
// reset.addEventListener('click', function(e) {
// score1.innerText = 0;
// score2.innerText = 0;
// num1 = 0;
// num2 = 0;
// player1.disabled = false;
// player2.disabled = false;
// score1.classList.remove('win-green');
// score1.classList.remove('lose-red');
// score2.classList.remove('win-green');
// score2.classList.remove('lose-red');
// select.value = "0"
// })