Skip to content

Instantly share code, notes, and snippets.

@jorenbroekema
Last active February 3, 2019 14:57
Show Gist options
  • Save jorenbroekema/c0326dcab7046e26550af8c4b438c90f to your computer and use it in GitHub Desktop.
Save jorenbroekema/c0326dcab7046e26550af8c4b438c90f to your computer and use it in GitHub Desktop.
simple Rock paper scissors
let choices = ['paper', 'rock', 'scissors'];
let playerChoice = prompt('What will you play? rock, paper or scissors?');
let opponentChoice = choices[Math.floor(Math.random() * 3)];
if (playerChoice === opponentChoice) {
alert('Opponent had: ' + opponentChoice + '. DRAW!');
} else if (playerChoice === 'paper' && opponentChoice === 'rock') {
alert('Opponent had: ' + opponentChoice + '. YOU WON :)!');
} else if (playerChoice === 'paper' && opponentChoice === 'scissors') {
alert('Opponent had: ' + opponentChoice + '. YOU LOST :(!');
} else if (playerChoice === 'rock' && opponentChoice === 'scissors') {
alert('Opponent had: ' + opponentChoice + '. YOU WON :)!');
} else if (playerChoice === 'rock' && opponentChoice === 'paper') {
alert('Opponent had: ' + opponentChoice + '. YOU LOST :(!');
} else if (playerChoice === 'scissors' && opponentChoice === 'paper') {
alert('Opponent had: ' + opponentChoice + '. YOU WON :)!');
} else if (playerChoice === 'scissors' && opponentChoice === 'rock') {
alert('Opponent had: ' + opponentChoice + '. YOU LOST :(!');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment