Skip to content

Instantly share code, notes, and snippets.

@nikolaswise
Created May 29, 2017 17:03
Show Gist options
  • Select an option

  • Save nikolaswise/1173b7e9bfaffc61d313a51064a48fe1 to your computer and use it in GitHub Desktop.

Select an option

Save nikolaswise/1173b7e9bfaffc61d313a51064a48fe1 to your computer and use it in GitHub Desktop.
// Get Nodes
var buttonA = document.getElementById('a');
var buttonB = document.getElementById('b');
// Define functions
var resultOne = function () {
alert('Thing One')
}
var resultTwo = function () {
alert('Thing Two')
}
var rollDice = function () {
// return a random number between 0 and 100
return Math.floor(Math.random() * 100)
}
var thingOne = function () {
var rando = rollDice();
if (rando < 75) {
resultOne()
} else {
resultTwo()
}
}
// Bind Events
buttonA.addEventListener('click', thingOne);
buttonB.addEventListener('click', thingTwo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment