Build a Rock, Paper, Scissors Game - Step 6

Tell us what’s happening:

Sorry, your code does not pass. You’re getting there.

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.

Your code so far

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

/* file: styles.css */

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

function getRoundResults(userOption, computerResult) {
  // normalize inputs to strings and lowercase for comparison & output
  const user = String(userOption).toLowerCase().trim();
  const comp = String(computerResult).toLowerCase().trim();

  // ensure global score variables exist (so increments won't throw)
  if (typeof globalThis !== "undefined") {
    if (typeof globalThis.playerScore === "undefined") globalThis.playerScore = 0;
    if (typeof globalThis.computerScore === "undefined") globalThis.computerScore = 0;
  }

  // tie case
  if (user === comp) {
    return `It's a tie! Both chose ${user}`;
  }

  // rules: what each option beats
  const beats = {
    rock: "scissors",
    paper: "rock",
    scissors: "paper"
  };

  // player wins
  if (beats[user] === comp) {
    globalThis.playerScore++;
    return `Player wins! ${user} beats ${comp}`;
  }

  // otherwise computer wins
  globalThis.computerScore++;
  return `Computer wins! ${comp} beats ${user}`;
}



// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:142.0) Gecko/20100101 Firefox/142.0

Challenge Information:

Build a Rock, Paper, Scissors Game - Step 6
https://www.freecodecamp.org/learn/full-stack-developer/workshop-rps-game/step-6

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

1 Like

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.

Please Tell us what’s happening in your own words.

Please do not just copy paste the error message.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

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

}

This is the seed code that was given, yet you have changed it, even adding another parameter. Reset this step. Follow the instructions and do only what is asked. Do not change the seed code.

If you have questions about your code, please post your updated code and do your best to explain what it is you do not understand and what steps you have taken to troubleshoot your code like adding console.log() statements to check variable and conditional values in your function.