-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscore_keeper.js
96 lines (83 loc) · 3.05 KB
/
score_keeper.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
const playerOneBtn = document.querySelector("#player1btn");
const playerTwoBtn = document.querySelector("#player2btn");
const resetBtn = document.querySelector("#reset");
const playerOneScore = document.querySelector("#playerOneScore");
const playerTwoScore = document.querySelector("#playerTwoScore");
const input = document.querySelector("#maxScore");
playerOneScore.value = "0";
playerTwoScore.value = "0";
let scoreOfOne = 0;
let scoreOfTwo = 0;
let winner = false ;
function scoreIncreaserbtn1(){
scoreOfOne = parseInt(playerOneScore.value);
if(playerOneScore.value < input.value && winner === false ){
scoreOfOne += 1 ;
}
playerOneScore.value = `${scoreOfOne}`;
playerOneScore.innerText = `${playerOneScore.value}`;
}
function scoreIncreaserbtn2(){
scoreOfTwo = parseInt(playerTwoScore.value);
if(playerTwoScore.value < input.value && winner === false ){
scoreOfTwo += 1 ;
}
playerTwoScore.value = `${scoreOfTwo}`;
playerTwoScore.innerText = `${playerTwoScore.value}`;
}
playerOneBtn.addEventListener('click', scoreIncreaserbtn1);
playerTwoBtn.addEventListener('click', scoreIncreaserbtn2);
function reset() {
scoreOfOne = 0;
scoreOfTwo = 0;
input.value = "";
}
playerOneBtn.addEventListener('click' , function(e){
console.log("btn 1 clicked")
if(playerOneScore.value == input.value){
if(playerOneScore.value < playerTwoScore.value){
playerOneScore.style.color = "red";
playerTwoScore.style.color = "green";
}
else {
playerOneScore.style.color = "green";
playerTwoScore.style.color = "red" ;
}
}
if(playerOneScore.value === input.value){
playerOneBtn.classList.add("disabled");
playerTwoBtn.classList.add("disabled");
winner = true ;
}
})
playerTwoBtn.addEventListener('click' , function(e){
console.log("btn 2 clicked");
if(playerTwoScore.value == input.value ){
if(playerOneScore.value < playerTwoScore.value){
playerOneScore.style.color = "red";
playerTwoScore.style.color = "green";
}
else {
playerOneScore.style.color = "green";
playerTwoScore.style.color = "red" ;
}
}
if(playerTwoScore.value === input.value){
playerOneBtn.classList.add("disabled");
playerTwoBtn.classList.add("disabled");
winner = true ;
}
})
resetBtn.addEventListener('click' , function(e){
console.log("btn reset clicked");
playerOneScore.value = "0";
playerTwoScore.value = "0";
input.value = "";
playerOneScore.innerText = `${playerOneScore.value}`;
playerTwoScore.innerText = `${playerTwoScore.value}`;
playerOneScore.style.color = "black";
playerTwoScore.style.color = "black";
playerOneBtn.classList.remove("disabled");
playerTwoBtn.classList.remove("disabled");
winner = false ;
})