Hii~
I am making RPS Game without UI
here I want to know how can i get prompt repeatedly if there’s a tie
Here’s My code so far:
const array = ["rock", "paper", "scissors"];
//to play theround
function playerRound(player, computer) {
if(player.toLowerCase() === computer) {
return repeatPrompt();
} else if(player.toLowerCase() === array[0] && computer === array[1]) {
return "You Lose";
} else if(player.toLowerCase() === array[0] && computer === array[2]) {
return "You Won";
} else if(player.toLowerCase() === array[1] && computer === array[0]) {
return "You won";
} else if(player.toLowerCase() === array[1] && computer === array[2]) {
return "You lose";
} else if(player.toLowerCase() === array[2] && computer === array[0]) {
return "You lose";
} else if(player.toLowerCase() === array[2] && computer === array[1]) {
return "You Won";
}
}
// parameters
const randomNumber = random();
const computer = array[0];
const playerR = prompt("Choose any one from the rock, paper, scissors");
// random Number
function random() {
return Math.floor(Math.random() * 2);
}
//repeating Prompt when The Player and Computer Choose Same
function repeatPrompt() {
const repeatAgain = "Y";
while(repeatAgain == "Y") {
return prompt("Choose any From RPS");
}
}
// Play the Game
console.log(playerRound(playerR, computer));
// return prompt repeatedly if it is not from rock, paper, scissors till it is equal to rock, paper, scissors
// return the prompt repeatedly if it theres a tie
//Make the Player play 5 rounds and repeat prompt if theres a tie
// return the score of 5 PlayRounds
//Declare Who wins and Looses