Skip to content

Instantly share code, notes, and snippets.

@ChrisBentley
Created April 8, 2016 14:21
Show Gist options
  • Save ChrisBentley/cc64af028c1fd9475d2ccdd3d1910eed to your computer and use it in GitHub Desktop.
Save ChrisBentley/cc64af028c1fd9475d2ccdd3d1910eed to your computer and use it in GitHub Desktop.
<script src="main.js"></script>
<button id='button1'>Click me</button>
window.addEventListener('DOMContentLoaded', function(event) {
var appState = {
buttonClicks: 0
};
function gavin(coffee) {
if (coffee.type == "ButtonClick") {
appState.buttonClicks++;
}
}
function drink() {
window.requestAnimationFrame(drink);
var button1 = document.getElementById("button1");
if (appState.buttonClicks > 0) {
button1.innerText = "You've clicked me " + appState.buttonClicks + " times!";
}
}
var button1 = document.getElementById("button1");
button1.addEventListener("click", function(event) {
var babycino = {
type: "ButtonClick"
};
gavin(babycino);
})
drink();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment