Achieve the given functionality using JS.
<!DOCTYPE html>
<html>
<head></head>
<body>
  <style>
    .counter-value {
      font-size: 36px;
      font-weight: 900;
    }
    .button {
      color: #ffffff;
      background-color: #0967d2;
      font-size: 14px;
      border-width: 0;
      border-radius: 4px;
      padding: 10px;
    }
  </style>
  <p id="counterValue" class="counter-value">0</p>
  <button id="decreaseBtn" class="button" onclick="onDecrement()">DECREASE</button>
  <button id="resetBtn" class="button" onclick="onReset()">RESET</button>
  <button id="increaseBtn" class="button" onclick="onIncrement()">INCREASE</button>
  <script>
    const counterValue = document.querySelector('#counterValue'),
       descreaseBtn = document.querySelector('#descreaseBtn'),
       resetBtn = document.querySelector('#resetBtn'),
       increaseBtn = document.querySelector('#increaseBtn');
     Â
    function onReset() {
      counterValue.innerHTML = 0
    }
    function onDecrement() {
      if (+counterValue.innerHTML % 2 == 1) {
        counterValue.innerHTML = +counterValue.innerHTML - 1;
      } else {
        counterValue.innerHTML = +counterValue.innerHTML - 2
      }
    }
    function onIncrement() {
      if (+counterValue.innerHTML % 2 == 1) {
        counterValue.innerHTML = +counterValue.innerHTML + 10;
      } else {
        counterValue.innerHTML = +counterValue.innerHTML + 5;
      }
    }
  </script>
</body>
</html>
Comments
Leave a comment