Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

96
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!