<div>
  <button id="button">Click</button>
  <p>Count: <span id="result"></span></p>
</div>
const result = document.querySelector('#result');
const button = document.querySelector('#button');
let clickCount = 0;

button.addEventListener('click', () => {
  clickCount++;
  updateClickCount();
});

updateClickCount();

function updateClickCount() {
  result.innerText = `${clickCount}`;
}
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.