Last active
February 3, 2019 14:57
-
-
Save jorenbroekema/c0326dcab7046e26550af8c4b438c90f to your computer and use it in GitHub Desktop.
simple Rock paper scissors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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