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

Tell us what’s happening:

if (hasPlayerWonTheRound(userOption, computerResult)) ,
Can someone to explain to me this, what does this mean

Your code so far

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

/* file: styles.css */

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

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

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

Challenge Information:

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

it means a function call with two parameter within if condition.

2 Likes

hasPlayerWonTheRound is called with two strings as the arguments.

userOption is the string argument getRoundResults was called with and computerResult is the string returned by getRandomComputerResult.

Inside hasPlayerWonTheRound the two string arguments are compared to the strings "Rock", "Paper", "Scissors" and the function will return a boolean true or false value, depending on the outcome of the conditional code.

The boolean value hasPlayerWonTheRound returns is then used as the condition for the if statement.

2 Likes

structure your if conditions better and make use of proper if , if else and else in your code . i found this thread helpful