Skip to content

Commit

Permalink
Trying To Fix Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Minemetero committed Jun 5, 2024
1 parent ae16739 commit 1b8967c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Table Tennis Counter</title>
<title>Pool Score Tracker</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Table Tennis Counter</h1>
<h1>Pool Score Tracker</h1>
<div class="input-group" id="initialSetup">
<label for="winBalls">Set Winning Balls: </label>
<input type="number" id="winBalls" value="5" min="1">
Expand Down
41 changes: 24 additions & 17 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,36 +60,43 @@ function startNewMatch() {
updateCurrentMatch();
}

function incrementCurrentMatchScore(playerName) {
function incrementScore(playerName) {
currentMatchScores[playerName]++;
updateCurrentMatch();
if (currentMatchScores[playerName] >= winBalls) {
totalScores[playerName]++;
document.getElementById('result').innerText = `${playerName} Wins this round!`;
setTimeout(() => {
document.getElementById('result').innerText = '';
updatePlayerScoreList();
updateMatchOrder();
updateMatchOrderList();
startNewMatch();
endMatch();
}, 2000);
}
}

function updateCurrentMatch() {
const match = document.getElementById('currentMatch');
const player1 = players[currentMatch[0]];
const player2 = players[currentMatch[1]];
match.innerHTML = `
<div class="player">
<label>${player1}: <span>${currentMatchScores[player1]}</span></label>
<button class="score-button" onclick="incrementCurrentMatchScore('${player1}')">Score</button>
</div>
<div class="player">
<label>${player2}: <span>${currentMatchScores[player2]}</span></label>
<button class="score-button" onclick="incrementCurrentMatchScore('${player2}')">Score</button>
</div>
`;
match.innerHTML = '';
players.forEach(player => {
const score = currentMatchScores[player] || 0;
const div = document.createElement('div');
div.className = 'player';
div.innerHTML = `
<label>${player}: <span>${score}</span></label>
<button class="score-button" onclick="incrementScore('${player}')">Score</button>
`;
match.appendChild(div);
});
}

function endMatch() {
Object.keys(currentMatchScores).forEach(player => {
totalScores[player] = totalScores[player] || 0;
totalScores[player] += currentMatchScores[player];
});
updatePlayerScoreList();
updateMatchOrder();
updateMatchOrderList();
startNewMatch();
}

function updatePlayerScoreList() {
Expand Down

0 comments on commit 1b8967c

Please sign in to comment.