Review DOM Manipulation by Building a Rock, Paper, Scissors Game - Step 5

Tell us what’s happening:

// running tests

  1. You should update the winnerMsgElement if there is a winner.
    // tests completed

Your code so far

<!-- file: index.html -->

/* file: script.js */
// User Editable Region

const playerScoreSpanElement = document.getElementById("player-score");
const computerScoreSpanElement = document.getElementById("computer-score");
const roundResultsMsg = document.getElementById("results-msg");
const winnerMsgElement = document.getElementById("winner-msg");
const optionsContainer = document.querySelector(".options-container");
const resetGameBtn = document.getElementById("reset-game-btn");

function showResults(userOption) {
  if (playerScore !== 3 && computerScore !== 3) {
    const result = getRoundResults(userOption); 
    roundResultsMsg.innerText = result;
    computerScoreSpanElement.innerText = computerScore;
    playerScoreSpanElement.innerText = playerScore;

    if (playerScore === 3 || computerScore === 3) {
      setTimeout(() => {
        let winnerMsg = playerScore === 3 
          ? "Player has won the game!" 
          : "Computer has won the game!";

        winnerMsgElement.textContent = winnerMsg;
        optionsContainer.style.display = 'none';
        resetGameBtn.style.display = "block";
      }, 1000); 
    }
  } else {
    winnerMsgElement.textContent = playerScore === 3 
      ? "Player has won the game!" 
      : "Computer has won the game!";
    optionsContainer.style.display = 'none';
    resetGameBtn.style.display = "block";
  }
}

// User Editable Region
/* file: styles.css */

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36

Challenge Information:

Review DOM Manipulation by Building a Rock, Paper, Scissors Game - Step 5

Hi there and welcome to our community!

You’ve got a bit tangled up in unnecessary code here.

Firstly, you don’t need the condition if (playerScore !== 3 && computerScore !== 3). You should be executing the four lines of code which follow it regardless.

The next condition (if (playerScore === 3 || computerScore === 3)) is fine.
However, I’m not sure what you’re trying to do after that.
Why the setTimeout?
Why the else clause, which essentially repeats the same logic as the if clause above it?