JavaScript - Step 4 of Rock, Paper, Scissors

I am working on ‘Review DOM Manipulation by Building a Rock, Paper, Scissors Game’. I am currently working on Step 4. I feel that I am answering correctly, but it keeps telling me I’m wrong. Here is my solution:

playerScoreSpanElement.innerText = playerScore;
computerScoreSpanElement.innerText = computerScore;
roundResultsMsg.innerText = getRoundResults(userOption);

Am I wrong? or is the system incorrectly flagging a problem? Did I make a typo that I can’t see?

please include a link to the step or use the Help button to create a forum topic with all the code and the link.

Sorry, but I don’t understand what you mean. there is a link button, but when I click it, it just says: “link copied”.
What do you want me to do?

Here is the code that I’ve done so far. I can’t find anything wrong with it…

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) {

};

showResults("Rock");

please paste the url (of the page you are on, or the step you are in) to your first post or your reply.

That’s the URL. I looked at step 5 and it had the same code as the code that I’d typed. I cut and pasted step 5 into step 4 and it was suddenly working. I must have made some kind of typo, but I swear… I just can’t see it. I must be doing something wrong, I guess.

You’re calling getRoundResults after the display for the round gets updated. That’s why your step is only working part of the time. Those parts of the time are only ties.

If we review the code for getRoundResults , we can see where the issue is.

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}`;
  }
}

If the player wins or the computer wins; their score gets updated.

Hope this helps.

1 Like

Hi there!
The challenge step is asking you to add new code within the above function.

Actually, I left it out of the reply, but it was there after clicking the button. I think it’s just me. Sorry to bother you folks. I’m obviously out of my depth here.

Did you find your mistake? I’m doing the exact same thing but it won’t budge

Hi there!

If you have any question about specific curriculum challenge. Create your own topic to the challenge step by using Help button. That button appears below the challenge editor, when you attempting wrong code more than three times.

Cheers, brother. I apologise for bothering everyone.