Skip to content

Instantly share code, notes, and snippets.

@Damimd10
Created March 24, 2019 03:37
Show Gist options
  • Save Damimd10/d6357bd327ea8fc4ad8c94c062c957cc to your computer and use it in GitHub Desktop.
Save Damimd10/d6357bd327ea8fc4ad8c94c062c957cc to your computer and use it in GitHub Desktop.
const heroes = [
{
name: 'Batman',
isFromDC: true,
info: function() {
console.log(`${this.name} is ${this.isFromDC ? '' : 'not '} from DC.`)
},
},
{
name: 'Spiderman',
isFromDC: false,
info: function() {
console.log(`${this.name} is ${this.isFromDC ? '' : 'not '} from DC.`)
},
},
]
function pickRandom(arr) {
return arr[Math.floor(Math.random() * arr.length)]
}
pickRandom(heroes).info()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment