Last active
June 26, 2017 18:24
-
-
Save bendavis78/480b04daeaa4f2fef3d89d1bf657df96 to your computer and use it in GitHub Desktop.
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
// Store an array of strings with each choice | |
var choices = [ | |
'rock', | |
'paper', | |
'scissors' | |
]; | |
// Store an array of strings with each image URL | |
var images = [ | |
'http://i.imgur.com/n6xptEr.png', | |
'http://i.imgur.com/n4bDRXp.png', | |
'http://i.imgur.com/E7loAXb.png' | |
]; | |
// Pick a random number between 1 and 3 | |
var randomIndex = Math.floor(Math.random() * 3) | |
// Use the randomIndex to pick a choice | |
var computerChoice = choices[randomIndex]; | |
// Use the same index to pick the right image from the array | |
var computerChoiceImage = images[randomIndex]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment