Skip to content

Instantly share code, notes, and snippets.

@jspooner
Created May 23, 2016 17:57
Show Gist options
  • Save jspooner/e041fa652b226cdb8ca7e71752d91bbb to your computer and use it in GitHub Desktop.
Save jspooner/e041fa652b226cdb8ca7e71752d91bbb to your computer and use it in GitHub Desktop.
<button id="btn-0">Button 1!</button>
<button id="btn-1">Button 2!</button>
<button id="btn-2">Button 3!</button>
<script type="text/javascript">
var prizes = ['A Unicorn!', 'A Hug!', 'Fresh Laundry!'];
var btnNum = 0;
for (var x = 0; x < prizes.length; x++) {
// for each of our buttons, when the user clicks it...
document.getElementById('btn-' + btnNum).onclick = function() {
// tell her what she's won!
alert(prizes[btnNum]);
};
btnNum = btnNum + 1;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment