Currently delving into the world of JavaScript, I've embarked on a project to create a console-based Rock Paper Scissors game. Here's the code snippet that I've come up with:
<!DOCTYPE html>
<html>
<body>
<script>
let RPS = function playRound (playerSelection, computerSelection) {
let playerSelection = promt ("What do you choose?", "");
let computerSelection = math.Random ();
if computerSelection (<0.34) {
computerSelection = "Rock";
} else if computerSelection (>=0.35 && <=0.66) {
computerSelection = "Paper";
} else {
computerSelection = "Scissors";
}
if (playerSelection === "Rock"){
if (computerSelection === "Scissors") {
console.log ("You win");
} else {
console.log ("You lose");
}
}
if (playerSelection === "Paper") {
if (computerSelection === "Scissors"){
console.log ("You win");
}else {
console.log ("You lose")
}
}
if (playerSelection === "Scissors") {
if (computerSelection ==== "Paper"){
console.log ("You win")
} else {
console.log ("You lose")
}
}
}
</script>
</body>
</html>
However, upon attempting to execute this code in the console, an error is thrown:
Uncaught SyntaxError: Identifier 'playerSelection' has already been declared
I'm puzzled about why this issue is arising. Can anyone shed some light on it?