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