Skip to content

Instantly share code, notes, and snippets.

@bendavis78
Last active June 26, 2017 18:24
Show Gist options
  • Save bendavis78/480b04daeaa4f2fef3d89d1bf657df96 to your computer and use it in GitHub Desktop.
Save bendavis78/480b04daeaa4f2fef3d89d1bf657df96 to your computer and use it in GitHub Desktop.
// 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