-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
108 lines (85 loc) · 2.86 KB
/
script.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
var p1Display = document.getElementById("p1");
var p1Score = 20;
p1Display.textContent = p1Score;
var p2Display = document.getElementById("p2");
var p2Score = 20;
p2Display.textContent = p2Score;
var p1Minus1Button = document.getElementById("p1Minus1");
var p1Plus1Button = document.getElementById("p1Plus1");
var p1Minus5Button = document.getElementById("p1Minus5");
var p1Plus5Button = document.getElementById("p1Plus5");
var p2Minus1Button = document.getElementById("p2Minus1");
var p2Plus1Button = document.getElementById("p2Plus1");
var p2Minus5Button = document.getElementById("p2Minus5");
var p2Plus5Button = document.getElementById("p2Plus5");
var p1cantLose = false;
var p2cantLose = false;
var p1CLButton = document.getElementById("p1cl");
var p2CLButton = document.getElementById("p2cl");
var resetButton = document.getElementById("reset");
p1Minus1Button.addEventListener("click", function(){
p1Score--;
p1Display.textContent = p1Score;
if (( p1Score <= 0) && !p1cantLose ){
p1Display.style.color = "red";
p2Display.style.color = "green";
}
});
p1Plus1Button.addEventListener("click", function(){
p1Score++;
p1Display.textContent = p1Score;
});
p1Minus5Button.addEventListener("click", function(){
p1Score = p1Score - 5;
p1Display.textContent = p1Score;
if (( p1Score <= 0) && !p1cantLose ){
p1Display.style.color = "red";
p2Display.style.color = "green";
}
});
p1Plus5Button.addEventListener("click", function(){
p1Score = p1Score + 5;
p1Display.textContent = p1Score;
});
p2Minus1Button.addEventListener("click", function(){
p2Score--;
p2Display.textContent = p2Score;
if (( p2Score <= 0) && !p2cantLose ){
p2Display.style.color = "red";
p1Display.style.color = "green";
}
});
p2Plus1Button.addEventListener("click", function(){
p2Score++;
p2Display.textContent = p2Score;
});
p2Minus5Button.addEventListener("click", function(){
p2Score = p2Score - 5;
p2Display.textContent = p2Score;
if (( p2Score <= 0) && !p2cantLose ){
p2Display.style.color = "red";
p1Display.style.color = "green";
}
});
p2Plus5Button.addEventListener("click", function(){
p2Score = p2Score + 5;
p2Display.textContent = p2Score;
});
p1CLButton.addEventListener("click", function(){
p1cantLose=!p1cantLose;
})
p2CLButton.addEventListener("click", function(){
p2cantLose=!p2cantLose;
})
resetButton.addEventListener("click", function(){
resetGame();
})
function resetGame(){
p1Score = p1Display.textContent = p2Score = p2Display.textContent = 20;
p1Display.style.color = p2Display.style.color = "black";
};
function refreshing(){
$('input[type="checkbox"]').each(function(){
$(this).prop('checked', false);
});
}