Skip to content

Commit

Permalink
Change endGame fo finish after X or O scores >=5 and start new round
Browse files Browse the repository at this point in the history
  • Loading branch information
atchutchi committed May 24, 2023
1 parent 4399832 commit 2875c55
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions assets/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,23 +186,29 @@ function startNextRound() {

// Function to stop the game after the last round
function endGame() {
gameInProgress = false;

if (playerXScore > playerOScore) {
gameInProgress = false;
if (playerXScore >= 5) {
alert("Player X wins the game!");
} else if (playerOScore > playerXScore) {
playerXScore = 0;
playerOScore = 0;
} else if (playerOScore >= 5) {
alert("Player O wins the game!");
playerXScore = 0;
playerOScore = 0;
} else {
alert("The game is a draw!");
return;
}

// Reset scores and current round to restart the game
playerXScore = 0;
playerOScore = 0;
currentRound = 1;
updateScores();

// Start the next round
startNextRound();
}


// Function to update the scores
function updateScores() {
document.getElementById("playerXScore").textContent = playerXScore;
Expand Down

0 comments on commit 2875c55

Please sign in to comment.