Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda