-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (44 loc) · 1.1 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
42
43
44
45
46
47
48
49
50
const dropbox = document.querySelector("#max")
const p1 = document.querySelector("#p1")
const p2 = document.querySelector("#p2")
const s1 = document.querySelector("#s1")
const s2 = document.querySelector("#s2")
const reset = document.querySelector("#reset")
let p1s = 0
let p2s = 0
let max = 5
dropbox.addEventListener("change", function() {
max = parseInt(this.value)
resetMe()
})
p1.addEventListener("click", function() {
p1s++
s1.innerText = p1s
if (p1s === max) {
s1.style.backgroundColor = "green"
s2.style.backgroundColor = "red"
p1.disabled = true
p2.disabled = true
}
})
p2.addEventListener("click", function() {
p2s++
s2.innerText = p2s
if (p2s === max) {
s2.style.backgroundColor = "green"
s1.style.backgroundColor = "red"
p1.disabled = true
p2.disabled = true
}
})
reset.addEventListener("click", resetMe)
function resetMe() {
p2s = 0
p1s = 0
s1.innerText = 0
s2.innerText = 0
s2.style.backgroundColor = ""
s1.style.backgroundColor = ""
p1.disabled = false
p2.disabled = false
}