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

Tell us what’s happening:

Not passing test, though it seems it’s working. Are they looking for something specific? Am I thinking of this all wrong?
Test that aren’t passing:

  1. Your playRound function should return the string “You win! [player choice] beats [computer choice]” if the player wins.
  2. Your playRound function should return the string “You lose! [computer choice] beats [player choice]” if the computer wins.

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 player = prompt('Please Enter Name:');
let computer ='Sheli';
let humanScore = 0;
let computerScore = 0;

let getComputerChoice = ()=>{
  let num = Math.floor(Math.random() * 3);
  return(hand[num]);
}

let getHumanChoice = ()=> {
  return prompt('rock, paper, or scissors');
}

let playRound = (humanChoice, computerChoice)=>{
  let finHuChoice = humanChoice.toLowerCase();

  switch(true){
    case finHuChoice == computerChoice:
      return 'It\'s a tie!';
    
    case finHuChoice == 'rock' && computerChoice == 'paper':
      computerScore++;
      return `You lose! ${computer} beats ${player}`;

    case finHuChoice == 'rock' && computerChoice == 'scissors':
      humanScore++;
      return `You win! ${player} beats ${computer}`;

    case finHuChoice == 'paper' && computerChoice == 'rock':
      humanScore++;
      return `You win! ${player} beats ${computer}`;

    case finHuChoice == 'paper' && computerChoice == 'scissors':
      computerScore++;
      return `You lose! ${computer} beats ${player}`;

    case finHuChoice == 'scissors' && computerChoice == 'rock':
      computerScore++
      return `You lose! ${computer} beats ${player}`;

    case finHuChoice == 'scissors' && computerChoice == 'paper':
      humanScore++;
      return `You win! ${player} beats ${computer}`;
    default:
  }
}

let playGame = ()=>{
  for (let i = 0; i<3; i++){
    console.log(`Round ${i+1}:  ${playRound(getHumanChoice(), getComputerChoice())}!`);
  }
  return humanScore>computerScore ? 'You win the game!' : 'You lose the game!'
}

console.log(playGame());

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36

Challenge Information:

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

hello and welcome to fcc forum :slight_smile:

  • i cant seem to see anything on screen, after entering my “choices” for each turns
  • if im not wrong, in your playHand method, you are not using “human choice/computer choice” in those return strings!!

happy coding :slight_smile:

Thank you so much! That was it. I thought they wanted us to give the players names. Instead they wanted us just to restate the choices. Again, thanks.

1 Like