Skip to content

Instantly share code, notes, and snippets.

@ejangi
Created November 23, 2023 02:54
Show Gist options
  • Save ejangi/96ea405a828fd57fece11d6469f01e05 to your computer and use it in GitHub Desktop.
Save ejangi/96ea405a828fd57fece11d6469f01e05 to your computer and use it in GitHub Desktop.
/*
// 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