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

95
Visualizações
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 à 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