Created
September 15, 2017 21:21
-
-
Save ggrumbley/721abac4eb335da458a3e3a826e832dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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