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

Tell us what’s happening:

Hello. There are some errors in my code. Please help my to find and correct them. Here is the description of them through the developer console: Sorry, your code does not pass. Keep trying.

Your getRoundResults should return a string. // running tests

  1. Your getRoundResults should return a string.
  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
    // console output
    [ReferenceError: getRoundResults is not defined]
    [ReferenceError: getRoundResults is not defined]

Your code so far

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

/* file: styles.css */

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

let playerScore = 0;
let computerScore = 0;
function getRandomComputerResult() {
    const choices = ["Rock", "Paper", "Scissors"];
    return choices[Math.floor(Math.random() * choices.length)];
}
function hasPlayerWonTheRound(playerOption, computerOption) {
    if (
        (playerOption === "Rock" && computerOption === "Scissors") ||
        (playerOption === "Paper" && computerOption === "Rock") ||
        (playerOption === "Scissors" && computerOption === "Paper")
    ) {
        return true;
    }
    return false;
}


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

    if (hasPlayerWonTheRound(userOption, computerResult)) {
        playerScore += 1;
        return `Player wins! ${userOption} beats ${computerResult}`;
    } else if (userOption === computerResult) {
        return `It's a tie! Both chose ${userOption}`;
    } else {
        computerScore += 1;
        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/128.0.0.0 Safari/537.36 OPR/114.0.0.0

Challenge Information:

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

This function works on my side and it seems correct. Can you try again? You can try disable all the extensions you have and set the browser zoom rate to 100%.

1 Like

Thank you very much. After the necessary changes in the browser, my code finally passed the test too.

1 Like