-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscoreKeepJS.js
More file actions
56 lines (44 loc) · 1.24 KB
/
scoreKeepJS.js
File metadata and controls
56 lines (44 loc) · 1.24 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
var playerOne = document.getElementById("player_one");
var playerTwo = document.getElementById("player_two");
var p1Display = document.querySelector("#p1Display");
var p2Display = document.querySelector("#p2Display");
var reset = document.getElementById("reset");
var p1Score = 0;
var p2Score = 0;
var gameOver = false;
var winningScore = 5;
var numInput = document.querySelector("input");
var winningScoreDisplay = document.querySelector("p span");
playerOne.addEventListener("click", function() {
if(!gameOver){
p1Score++;
if(p1Score === winningScore) {
p1Display.classList.add("winner");
gameOver = true;
}
p1Display.textContent = p1Score;
}
});
playerTwo.addEventListener("click", function() {
if(!gameOver) {
p2Score++;
}
if(p2Score === winningScore) {
p2Display.classList.add("winner");
gameOver = true;
}
p2Display.textContent = p2Score
})
reset.addEventListener("click", function() {
gameOver = false;
p1Score = 0;
p1Display.textContent = p1Score;
p1Display.classList.remove("winner");
p2Score = 0;
p2Display.textContent = p2Score;
p2Display.classList.remove("winner");
})
numInput.addEventListener("change", function() {
winningScoreDisplay.textContent = numInput.value;
winningScore = Number(numInput.value);
})