-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
78 lines (65 loc) · 2.32 KB
/
app.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
const playerOneButton = document.querySelector(".playerOneButton");
const playerTwoButton = document.querySelector(".playerTwoButton");
const resetButton = document.querySelector(".resetButton");
const scoreSelector = document.querySelector("#score");
const playerOne = document.querySelector(".playerOne");
const playerTwo = document.querySelector(".playerTwo");
const results = document.querySelector(".results");
const h2 = document.querySelector("h2").textContent.trim();
let playerOneScore = 0;
let playerTwoScore = 0;
let isGameOver = false;
// PLAYER ONE SETTINGS
playerOneButton.addEventListener("click", () => {
if(winningScore !== 0){
if(!isGameOver){
playerOneScore ++;
if(playerOneScore === winningScore){
isGameOver = true;
playerOne.classList.add("winner");
playerTwo.classList.add("loser");
results.innerHTML = "";
let p = document.createElement("p");
p.textContent = "Zápas skončil."
results.appendChild(p);
}
playerOne.textContent = playerOneScore;
}
}});
// PLAYER TWO SETTINGS
playerTwoButton.addEventListener("click", () => {
if(winningScore !== 0){
if(!isGameOver){
playerTwoScore ++;
if(playerTwoScore === winningScore){
isGameOver = true;
playerOne.classList.add("loser");
playerTwo.classList.add("winner");
results.innerHTML = "";
let p = document.createElement("p");
p.textContent = "Zápas skončil."
results.appendChild(p);
}
playerTwo.textContent = playerTwoScore;
}
}});
// SCORE SELECTOR
scoreSelector.addEventListener("change", function () {
winningScore = parseInt(this.value);
console.log(parseInt(this.value));
reset();
});
// RESET FUNCTION
resetButton.addEventListener("click", reset);
function reset (){
isGameOver = false;
playerOneScore = 0;
playerTwoScore = 0;
playerOne.textContent = 0;
playerTwo.textContent = 0;
playerOne.classList.remove("winner");
playerOne.classList.remove("loser");
playerTwo.classList.remove("winner");
playerTwo.classList.remove("loser");
results.innerHTML = "";
}