Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

64
Views
JS Rock Paper Scissor project. Doesnt prompt new selections for each round

At the infant stages of learning JS. My RPS project works for the most part... The problem I cannot get around is that the game is calling for a 'human' input and computer selection once, then runs this selection 5x instead of calling for a new selection for each round. I've beat my head on this for several days to no avail.

let person = prompt(
    'What will it be? Rock, Paper, or Scissors.'
);
person = person.toUpperCase();
console.log(person); // show human selection
let computer = [
    Math.floor(Math.random() * 3) + 1
];

let roundCount = 0;
let humanWins = 0;
let compWins = 0;

if (computer == 1) {
    computer = 'ROCK';
} else if (computer == 2) {
    computer = 'PAPER';
} else if (computer == 3) {
    computer = 'SCISSORS';
} else {
    computer = 'No true statements';
}
console.log(computer); // show comp selection

function playGame(peep, comp) {
    roundCount++;
    if (peep === comp) {
        console.log('Tie', +roundCount);
        return 'Tie';
    } else if (
        (peep === 'ROCK' &&
            comp === 'SCISSORS') ||
        (peep === 'PAPER' && comp === 'ROCK') ||
        (peep === 'SCISSORS' && comp === 'PAPER')
    ) {
        humanWins++;
        console.log(
            'Human wins this round',
            +roundCount,
            +humanWins
        );
        return 'Human wins this round';
    } else {
        compWins++;
        console.log(
            'Skynet wins this round',
            +roundCount,
            +compWins
        );
        return 'Skynet wins this round';
    }
}

function game() {
    for (let i = 0; i <= 5; i++)
        if (humanWins === 5 || compWins === 5) {
            console.log('game over');
        } else {
            playGame(person, computer);
        }
    return humanWins, compWins;
}

game();
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
  <script src='script.js'></script>
  <script>
   
  </script>
</body>
</html>

I don't understand why it takes a single round and runs that result 5 times.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!