This is a simple JavaScript project that demonstrates how to create a click counter. Every time the button is clicked, the counter value increments by 1 and updates on the screen. This project is great for beginners to understand basic DOM manipulation and event handling in JavaScript.
- Language: JavaScript
- HTML: Basic structure with an
<h2>
tag to display the counter and a button to increment it. - JavaScript Features:
- Initializes a counter.
- Uses a button click event to increment and display the updated counter.
- Simple button to increment the counter.
- Real-time display of counter value.
- Minimal and easy-to-follow code structure.
-
Clone the repository or download the files to your local machine.
git clone https://github.com/narnacle/javascript-counter.git
-
Open the
index.html
file in any web browser to see the counter in action.
- HTML: Displays a counter initialized at 0, and a button that calls a JavaScript function.
- JavaScript:
- Initializes a variable
count
to store the current counter value. - Defines
incrementCounter()
function, which incrementscount
by 1 and updates the HTML display.
- Initializes a variable
<h2>Counter: <span id="counter">0</span></h2>
<button onclick="incrementCounter()">Click Me!</button>
<script>
let count = 0;
function incrementCounter() {
count += 1;
document.getElementById("counter").innerText = count;
}
</script>
- Open the
index.html
file in a browser. - Click the "Click Me!" button to see the counter increment by 1 on each click.
This project is open-source and available under the MIT License.
- Inspired by beginner JavaScript tutorials and small web projects.
- Thanks to the open-source community for resources and inspiration.