Skip to content

Update script.js#1

Open
ussingdi wants to merge 1 commit into
mainfrom
TEST1
Open

Update script.js#1
ussingdi wants to merge 1 commit into
mainfrom
TEST1

Conversation

@ussingdi
Copy link
Copy Markdown
Owner

No description provided.

@ai-coding-app
Copy link
Copy Markdown

ai-coding-app Bot commented Nov 23, 2024

  1. You can simplify the addition of the current score to the active player's score by using the compound assignment operator:
scores[activePlayer] += currentScore;
  1. In the if statement, you can remove the else clause and move the switchPlayer() function call outside of it, since it will always be executed when the if condition is not met:
if (scores[activePlayer] >= 100) {
  // Finish the game
  playing = false;
  diceEl.classList.add('hidden');

  document
    .querySelector(`.player--${activePlayer}`)
    .classList.add('player--winner');
    .classList.remove('player--active');

  switchPlayer();
}

if (playing) {
  // Roll the dice
  ...
}
  1. You can chain the add and remove classList methods to reduce the number of method calls:
document
  .querySelector(`.player--${activePlayer}`)
  .classList.add('player--winner')
  .classList.remove('player--active');
  1. You can use the textContent property to update the score element, which is more efficient than using innerText:
document.getElementById(`score--${activePlayer}`).textContent = scores[activePlayer];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant