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

Tell us what’s happening:

Although I have completed this task I can’t figure how why
“else if (hasPlayerWonTheRound === computerResult)” makes sense. We are comparing a boolean value (true or false) with a string (Rock, Paper or Scissor) how can this be part of the solution?

Your code so far

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

/* file: styles.css */

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

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

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

console.log(getRoundResults("Rock"));
console.log("Player Score: ", playerScore, "Computer Score: ", computerScore);

// 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/122.0.0.0 Safari/537.36

Challenge Information:

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

You’re function doesn’t pass the tests for me.

First there’s a syntax error and then your tie condition doesn’t seem to work?

// running tests
2. Your getRoundResults function should return the correct message based on who wins the round. If no one wins, the message should say it's a tie.
// tests completed

As well, hasPlayerWonTheRound is the name of the function, but it’s not actually calling the function, so it doesn’t return a boolean

Hi @fadigascodex

image

When I fix up the syntax errors, the code does pass.
It looks like the tests don’t actually test if a tie outputs the correct message, the else if condition is never satisfied.

Happy coding

I took the other “+” out on purpose so I could post this on the forum, otherwise it wouldn’t let me, if I add the + it passes.

Althought this code passes:
//

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

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

console.log(getRoundResults("Rock"));
console.log("Player Score: ", playerScore, "Computer Score: ", computerScore);

//
I do want to improve it, how can I improve the tie condition? As I seriously think it is wrong and needs some work.

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

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

console.log(getRoundResults("Rock"));
console.log("Player Score: ", playerScore, "Computer Score: ", computerScore);

This looks way better ?

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

1 Like

Hi @fadigascodex

The else if condition now checks if both the user and computer tie.

Happy coding

No it doesn’t?

// running tests
2. Your getRoundResults function should return the correct message based on who wins the round. If no one wins, the message should say it's a tie.

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

It does pass the tests :+1: