ISSUE: Trying to create a people counter, where every time Increment button is clicked the count should increase by 1. But when I m clicking Increment button nothing is happening. Please help to fix the issue
JS code
code:
HTML code
2
Try this:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>People Counter</title> </head> <body> <h1>People Counter</h1> <p>Count: <span id="count">0</span></p> <button onclick="incrementCount()">Increment</button> <script> // JavaScript code let count = 0; function incrementCount() { count++; document.getElementById('count').innerText = count; } </script> </body> </html>
You have to call increment() function in the button click. Also move
let countE1 = document.getElementById("count-e1");
inside the increment() function.
Click here to cancel reply.
2
Answers
Try this:
You have to call increment() function in the button click. Also move
inside the increment() function.