-1

I want the value of offset variable to increase by 10 whenever the button is clicked. Currently, when I click on the next button, I get 2 lines: 0 and then 010. How do i get the value to change only when the button is clicked, and incremented at each click?

const New = () => {
// extract query parameters from url
const queryStr = '?offset=0&limit=5'
const usp = new URLSearchParams(queryStr)
let newVar = usp.get ('offset')
console.log(newVar)

// Set increment 

let offset = newOffset += 10
console.log('new', offset)
}

const next = document.getElementById("next");
next.addEventListener("click", (event)=> New());
Yin
  • 11
  • 5
  • The first `0` is presumably from `console.log(newVar)` - so if you don't want it, remove it. And the `010` issue, see duplicate. – CBroe May 20 '22 at 11:49

0 Answers0