'Rock Paper Scissors Game--Prompt() Loop and Scoreboard

the program is intended to run the normal rock paper scissors game with the computer's output being randomised. This is the first part and I have no issue with it, but I am just appending the code so a full picture can be gotten.

function computerPlay() {
  let choices = ["Rock", "Paper", "Scissors"];
  return choices[Math.floor(Math.random() * choices.length)]
}

let playerSelection = prompt("choose Rock,Paper or Scissors");

let computerSelection = computerPlay();

function playRound(playerSelection, computerSelection) {
  //player chooses rock//
  if ((playerSelection.toUpperCase() === "ROCK") && (computerSelection === "Paper")) {
    return ("You lose,Paper beats Rock!");
  } else if ((playerSelection.toUpperCase() === "ROCK") && (computerSelection === "Rock")) {
    return ("It's a tie.");
  } else if ((playerSelection.toUpperCase() === "ROCK") && (computerSelection === "Scissors")) {
    return ("You win,Rock beats Scissors!");
  }
  //player chooses scissors//
  if ((playerSelection.toUpperCase() === "SCISSORS") && (computerSelection === "Rock")) {
    return ("You lose,Rock beats Scissors!");
  } else if ((playerSelection.toUpperCase() === "SCISSORS") && (computerSelection === "Scissors")) {
    return ("It's a tie.");
  } else if ((playerSelection.toUpperCase() === "SCISSORS") && (computerSelection === "Paper")) {
    return ("You win, Scissors beats paper!");
  }
  //player chooses paper//
  if ((playerSelection.toUpperCase() === "PAPER") && (computerSelection === "Scissors")) {
    return ("You lose,Scissors beats Paper!");
  } else if ((playerSelection.toUpperCase() === "PAPER") && (computerSelection === "Paper")) {
    return ("It's a tie.");
  } else if ((playerSelection.toUpperCase() === "PAPER") && (computerSelection === "Rock")) {
    return ("You win, Paper beats Rock!")
  }
}

The second part is to loop the game 5 times and this is where I have not been able to make the prompt() window appear 5 instances. It records the first input and just repeat it 4 other times; same goes to the computer's selection.

function game() {
  for (let i = 0; i < 5; i++) {
    console.log(playerSelection, computerSelection);
  }
}

game();

The last part is the scoreboard and although the loops are randomised, no output is seen in the console and when the function is called it returns 0. The code is similar to the first part of the code and only return is different.

function scoreboard() {
  let playerScore = 0;
  x = playerScore;
  let computerScore = 0
  y = computerScore
  //player chooses rock//
  if ((playerSelection.toUpperCase() === "ROCK") && (computerSelection === "Paper")) {
    return (Number(x), (Number(y) + 1));
  } else if ((playerSelection.toUpperCase() === "ROCK") && (computerSelection === "Rock")) {
    return (Number(x), Number(y));
  } else if ((playerSelection.toUpperCase() === "ROCK") && (computerSelection === "Scissors")) {
    return (Number(x) + 1), Number(y);
  }
  //player chooses scissors//
  if ((playerSelection.toUpperCase() === "SCISSORS") && (computerSelection === "Rock")) {
    return (Number(x), (Number(y) + 1));
  } else if ((playerSelection.toUpperCase() === "SCISSORS") && (computerSelection === "Scissors")) {
    return (Number(x), Number(y));
  } else if ((playerSelection.toUpperCase() === "SCISSORS") && (computerSelection === "Paper")) {
    return (Number(x) + 1), Number(y);
  }
  //player chooses paper//
  if ((playerSelection.toUpperCase() === "PAPER") && (computerSelection === "Scissors")) {
    return (Number(x), (Number(y) + 1));
  } else if ((playerSelection.toUpperCase() === "PAPER") && (computerSelection === "Paper")) {
    return (Number(x), Number(y));
  } else if ((playerSelection.toUpperCase() === "PAPER") && (computerSelection === "Rock")) {
    return (Number(x) + 1), Number(y);
  }

  if (x > y) {
    console.log("PLAYER WON");
  } else if (x < y) {
    console.log("COMPUTER WON");
  }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source