Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

427
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda