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

413
Visualizações
ClearInterval is executed multiple times in one execution - How to fix it?

I am trying to build a ludo game using JavaScript & Jquery. So I want the pieces to move step by step. So for that, I wrote this code -

        function moveHorse() {
    
        $('td > img').click(function(event){

    
            // ludo baby steps 
            newfunc = setInterval(function(){
              //Some Code
            },300);
            setTimeout(function(){
                clearInterval(newfunc);
            }, randomDice*300);
        });
    }

The code is working really well. Interval is stopped based on the dice number. But it works only for one time for each player.

When the user clicks on the pieces for the second time the interval is set but it never stops. I found the issue and it's happening bcoz, after the first try, the Interval is executed multiple times in a single execution.

I just want to know how I can fix it.

Please check this video to better understand my issue - https://youtu.be/7d8A8qB5TG8

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The problem was multiple function executions at one time. During the first move, the moveHorse function was executed only once. But after that, it was executed 3-7 times on every click.

I found one Stackoverlfow answer that solved my issue. Link of the answer - Javascript - prevent function from executing multiple times

about 4 years ago · Juan Pablo Isaza Relatório
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