increment button starting from zero instead of one

I wrote the code to display 0 until the increment button is clicked but it starts from one.

let countEl = document.getElementById("count-el")
console.log(countEl)

let count = 0;

function peopleEntered() {
  count = count + 1;
  countEl.innerText = count;
  console.log(count);
}
peopleEntered();
<div class="countapp">
  <h1>People Entered: </h1>
  <h2 id="count-el">0 </h2>
  <button type="button" id="increment-btn" onclick="peopleEntered()"> INCREMENT </button>
  <script src="index.js">
  </script>
</div>

enter image description here



Read more here: https://stackoverflow.com/questions/68473875/increment-button-starting-from-zero-instead-of-one

Content Attribution

This content was originally published by Davinci at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: