Skip to content

Instantly share code, notes, and snippets.

@ggrumbley
Created September 15, 2017 21:21
Show Gist options
  • Save ggrumbley/721abac4eb335da458a3e3a826e832dd to your computer and use it in GitHub Desktop.
Save ggrumbley/721abac4eb335da458a3e3a826e832dd to your computer and use it in GitHub Desktop.
<head>
</head>
<body>
<button>Click!</button>
<script>
function startGame() {
let counter = 0;
document.querySelector('button').addEventListener('click', () => {
++counter;
});
return new Promise((resolve, reject) => {
setTimeout(() => {
if (counter > 5) {
resolve();
} else {
reject();
}
}, 2000)
});
}
startGame()
.then(() => alert('You win!'))
.catch(() => alert('You lost!'));
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment