Created
November 23, 2023 02:54
-
-
Save ejangi/96ea405a828fd57fece11d6469f01e05 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
// Usage: | |
<button id="counter" type="button"></button> | |
import { setupCounter } from './counter.js' | |
setupCounter(document.querySelector('#counter')) | |
*/ | |
export function setupCounter(element) { | |
let counter = 0 | |
const setCounter = (count) => { | |
counter = count | |
element.innerHTML = `count is ${counter}` | |
} | |
element.addEventListener('click', () => setCounter(counter + 1)) | |
setCounter(0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment