-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscorekeeper.js
73 lines (57 loc) · 1.22 KB
/
scorekeeper.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
var p1button= document.querySelector(".p1");
var p2button= document.querySelector(".p2");
var p3button= document.querySelector(".p3");
var disp1= document.querySelector("#p1Display");
var disp2=document.querySelector("#p2Display")
var wingameDisplay=document.querySelector("#scoredisp")
var num=document.querySelector("input")
var gameover=false;
var wingamescore=5;
var h1=document.querySelector("h1");
var Score=0;
p1button.addEventListener("click",function()
{
if(!gameover)
{
Score++;
if (Score===wingamescore)
{
gameover=true;
disp1.classList.add("winner");
}
disp1.textContent=Score;
}
});
var p2Score=0;
p2button.addEventListener("click",function()
{
if(!gameover)
{
p2Score++;
if (p2Score===wingamescore)
{
gameover=true;
disp2.classList.add("winner");
}
disp2.textContent=p2Score;
}
});
function reset()
{
Score=0;
p2Score=0;
disp2.textContent=0;
disp1.textContent=0;
disp1.classList.remove("winner");
disp2.classList.remove("winner");
gameover=false;
}
p3button.addEventListener("click", function()
{
reset();
});
num.addEventListener("change", function(){
wingameDisplay.textContent= num.value;
wingamescore=Number(num.value);
reset();
});