-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScoreKeeper.js
63 lines (50 loc) · 1.29 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
var P1=document.getElementById("p1");
var P2=document.querySelector("#p2");
var P1Dis=document.getElementById("p1Display");
var P2Dis=document.getElementById("p2Display");
var Res=document.querySelector("#res");
var numInput=document.querySelector("input[type=number]");
var gameOver=false;
var WinningScore=5;
var playingNum=document.querySelector("p span");
var p1Score=0;
var p2Score=0;
P1.addEventListener("click",function(){
if(!gameOver){
p1Score++;
if(p1Score==WinningScore)
{
P1Dis.classList.add("winner");
gameOver=true;
}
P1Dis.textContent=p1Score;
}
});
P2.addEventListener("click",function(){
if(!gameOver){
p2Score++;
if(p2Score==WinningScore)
{
P2Dis.classList.add("winner");
gameOver=true;
}
P2Dis.textContent=p2Score;
}
});
Res.addEventListener("click",function(){
reset();
});
function reset(){
p1Score=0;
p2Score=0;
P1Dis.textContent=p1Score;
P2Dis.textContent=p2Score;
P1Dis.classList.remove("winner");
P2Dis.classList.remove("winner");
gameOver=!gameOver;
};
numInput.addEventListener("change",function(){
playingNum.textContent=numInput.value;
WinningScore=numInput.value;
reset();
});