I have the following function:
(The array contains HTML DOM elements created by js)
function run(box,pos) {
setInterval(() => {
i = pos[0]
if (i > box.length - 1) {
i = 0
box[box.length - 1].classList.remove('color')
}
if (i > 0) {
box[i - 1].classList.remove('color')
}
box[i].classList.add('color')
i++
pos.unshift(i)
pos.pop()
console.log(pos)
}, 500)
}
There are three arrays (box) and three positions(pos) as parameters.
The first runs default at the beginning then on pressing a button I want it to stop and run the same function with second parameters and again on pressing the button with third parameters and after that when button is pressed the function should start with the first parameters as a loop.
There's only one button.