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

Tell us what’s happening:

I do not know what I did wrong but it keeps on giving me errors

Your code so far

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

/* file: styles.css */

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

const playerScoreSpanElement = document.getElementById("player-score");
const computerScoreSpanElement = document.getElementById("computer-score");
const roundResultsMsg = document.getElementById("results-msg");

function showResults(userOption) {
  playerScoreSpanElement.innerText = playerScore
  computerScoreSpanElement.innerText = computerScore
  roundResultsMsg.innerText = getRoundResults(userOption)
};

showResults("Rock");

// User Editable Region

Your browser information:

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

Challenge Information:

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

1 Like

Welcome to the forum :wave:

What error? Often the error will contain a clue to the solution.

It keeps on say " Your showResults function should update the roundResultsMsg with the result of the round." but I have no clue what that means

That’s not true because you’ve implemented it perfectly.

There is a problem though. You are updating the displayed score and then calling the getroundresults function.

What is in the getRoundResults(userOption) function? What does it do?

well it takes a parameter (userOption) then returns depending on the result of the game, it returns with string ouput

Does it update any global variables?

Yes it does, But shouldnt it as the return value?

consider what global variables it is updating, are they involved in the function tou are writing now?

I’m sorry I don’t understand your question, can you rephrase it?

Which global variables does it update?

Same here, i didn’t figure out where i am going wrong,
Correct me if I am wrong:
“playerScoreSpanElement.innerText” is updated by the “playerScore”.
“computerScoreSpanElement.innerText” is update by the “computeScore”.
there values are updated in “getRoundResults” function.

function getRandomComputerResult() {
  const options = ["Rock", "Paper", "Scissors"];
  const randomIndex = Math.floor(Math.random() * options.length);
  return options[randomIndex];
}

function hasPlayerWonTheRound(player, computer) {
  return (
    (player === "Rock" && computer === "Scissors") ||
    (player === "Scissors" && computer === "Paper") ||
    (player === "Paper" && computer === "Rock")
  );
}

let playerScore = 0;
let computerScore = 0;

function getRoundResults(userOption) {
  const computerResult = getRandomComputerResult();

  if (hasPlayerWonTheRound(userOption, computerResult)) {
    playerScore++;
    return `Player wins! ${userOption} beats ${computerResult}`;
  } else if (computerResult === userOption) {
    return `It's a tie! Both chose ${userOption}`;
  } else {
    computerScore++;
    return `Computer wins! ${computerResult} beats ${userOption}`;
  }
}

const playerScoreSpanElement = document.getElementById("player-score");
const computerScoreSpanElement = document.getElementById("computer-score");
const roundResultsMsg = document.getElementById("results-msg");

function showResults(userOption) {
  playerScoreSpanElement.innerText = playerScore;
  computerScoreSpanElement.innerText = computerScore;
  roundResultsMsg.innerText = getRoundResults(userOption);
};

showResults("Rock");

This is Working.
Just change the order of the code :

code removed by moderator

This is Working.

hi @HardikVijeta

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

1 Like