addEventListener of adding 1 on each click

  javascript

I have created 2 buttons and a display windows. I want the display windows can add 1 if I click + button. I want the display windows can subtract 1 if I click – button.
However, the function seems doesnt works. May I know what is the problem of my code:

let addButton = document.getElementById('add');
let subtractButton = document.getElementById('subtract');
let humanGuess = document.getElementById('human-guess');

function addNum() {
  humanGuess.value = +humanGuess.value + 1;
}

addButton.addEventListener('click', addNum)

function subtractNum() {
  humanGuess.value = -humanGuess.value - 1;
}

subtractButton.addEventListener('click', subtractNum)
<div class="number-controls">
  <input type="number" id="human-guess" min=0 max=9 value=0>
  <button class="number-control left" id="subtract">-</button>
  <button class="number-control right" id="add">+</button>
</div>

Source: Ask Javascript Questions

LEAVE A COMMENT