Challenge: Counter
Build a simple website that contains a counter. The site should display a number and two buttons - one to increment the number and one to decrement it.
Hints
- How do you get a reference to an HTML element using JavaScript?
- How do you listen for click events on a button element?
- How do you update the HTML of an element on the page?
Take It Further
- Instead of using existing HTML elements, use JavaScript to draw the buttons and the number to the page when you open the website.
- Now that you can draw one counter using JavaScript, try adding a button that will let you add multiple counters
- Now that you have multiple counters, give each one a "name" input field and a button to remove it from the page
- How might you use localStorage to persist your counters across page loads?
Example Solution