Build a Rock Paper Scissor Game - Build a Rock Paper Scissors Game

Tell us what’s happening:

always saying
14. You should return the winner of the game based on who won the most rounds.

Your code so far

<!-- file: index.html -->
<html lang="en">
<head>
  <script src="script.js"></script>
</head>
</html>
/* file: script.js */
const hand = ['rock', 'paper', 'scissors'];

let humanScore = 0;
let computerScore = 0;


const getComputerChoice = () => {
  const computerChoice = Math.floor((Math.random() * 3) + 1)
  switch (computerChoice) {
    case 1:
      return "rock";
    case 2:
      return "paper";
    case 3:
      return "scissors";
  }
}

const getHumanChoice = () => {
  // const choice = prompt("Rock, Paper, or Scissors?")
  while (!hand.includes(choice)) {
    // choice = prompt("Invalid choice! Please enter Rock, Paper, or Scissors:");
  }
  return choice;
}

const playRound = (humanChoice, computerChoice) => {
  const human = humanChoice.toLowerCase();
  const computer = computerChoice;
  const youWin = `You win! ${human} beats ${computer}`;
  const youLose = `You lose! ${computer} beats ${human}`;

  if (human === computer) {
    return "It's a tie!"
  }

  if (
    (human === "rock" && computer === "scissors") ||
    (human === "paper" && computer === "rock") ||
    (human === "scissors" && computer === "paper")
  ) {
    humanScore++;
    return youWin;
  } else {
    computerScore++;
    return youLose;
  }
}

const playGame = () => {
  let rounds = 3;
  for (let i = 1; i = rounds; i++) {
    const humanChoice = getHumanChoice();
    const computerChoice = getComputerChoice();
    playRound(humanChoice, computerChoice);
  }

  if (humanScore > computerScore) {
    return "You win the game!";
  } else {
    return "You lose the game!";
  }
}


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0

Challenge Information:

Build a Rock Paper Scissor Game - Build a Rock Paper Scissors Game

Welcome to the forum @earllfortuna.gt

How does the human player input their choice?

Happy coding

1 Like

Thank you for the warm greetings,

The human input their choices via prompt, inputting string. It is currently commented out since it runs in infinite loop and stops me from continuing in navigating the browser