JSFiddle - React, Tailwind, and code Playground

HTML

<div id='#content'>
  <button id='button1'>
    Add 0
  </button>
  <button id='button2'>
    Add 1
  </button>
    <button id='button3'>
    Add 2
  </button>
</div>
<div>
counter: <span id='counter'>0</span>
</div>

JavaScript

let counter = 0

const counterElement = document.getElementById('counter')
const button1 = document.getElementById('button1');
const button2 = document.getElementById('button2');
const button3 = document.getElementById('button3');
const buttons = [button1, button2, button3]



for (var i = 0; i < 3; i++) {
    const localValue = i
    buttons[i].onclick = function()
    {
        counter += localValue;
        counterElement.innerHTML = counter
    };
}