Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
How to execute same functions using different parameters in a loop whenever a button is clicked

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!