Skip to content

Instantly share code, notes, and snippets.

@thisiskeanyvy
Created August 2, 2022 20:53
Show Gist options
  • Save thisiskeanyvy/70f521edc47e2bc9830828accd33d894 to your computer and use it in GitHub Desktop.
Save thisiskeanyvy/70f521edc47e2bc9830828accd33d894 to your computer and use it in GitHub Desktop.
Rock Paper Scissors (2 players)
function rockPaperScissors() {
var player1 = prompt("Player 1, choose rock, paper, or scissors");
var player2 = prompt("Player 2, choose rock, paper, or scissors");
if (player1 === player2) {
alert("It's a tie!");
} else if (player1 === "rock") {
if (player2 === "scissors") {
alert("Player 1 wins!");
} else {
alert("Player 2 wins!");
}
} else if (player1 === "paper") {
if (player2 === "rock") {
alert("Player 1 wins!");
} else {
alert("Player 2 wins!");
}
} else if (player1 === "scissors") {
if (player2 === "paper") {
alert("Player 1 wins!");
} else {
alert("Player 2 wins!");
}
} else {
alert("Please enter a valid choice");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment