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

92
Vistas
setInterval triggering faster than set

I am trying to build a dinosaur running game in React much like google chrome's.

My idea is that I will run a function at the exact moment the object is suppose to hit the dinosaur, around 3 seconds

  function check4Death() {
        if (playerClass !== '') {
          console.log('safe')
        }
        else {
          console.log('nope')
          clearInterval()
        }
         }
    setInterval(check4Death, 3000)

This function checks to see if the player is currently in the air
As my method of jumping is adding and then removing a class from my playerClass object

  function Jump() {
    setPlayerClass('jump')
    setTimeout(() => {
      setPlayerClass('')
    }, 500);
  }

Instead of the function telling me either safe or nope every three seconds, I get this enter image description here

I am very confused as to why this is happening, I have a link to my full code here

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