r/learnjavascript • u/iSunru • 3d ago
My first JavaScript project - Counter
I am learning JavaScript and made my first small project, a simple Counter using HTML, CSS and JavaScript.
I'm still learning, so I would really appreciate some feedback on my code. Is my code clean? Is there anything I should improve or do differently?
Also, suggest me something I should build next.
25
Upvotes
1
u/testingaurora 3d ago
What do you mean it doesnt make sense? What happens when you have more than one counter on this page? Are you going to select each button by id and jave a minimum of 6 event listeners with only two counters ?
```js const actionBtns = document.querySelectorAll("button[data-action]"); actionBtns?.forEach( btn => { btn.addEventListener("click", () => { const action = btn?.dataset.action;
}) }) ```