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

270
Views
how to change the attribute of an object after n seconds using setTimeout

enter image description herehttps://github.com/sarang997/simulation1 Here is the simulation I am working on. You can try running the html file for it to work. There are circles colliding with each other in the simulation. Whenever a red circle collides with the green circle it changes the color of the green circle to red. Now what I want is as soon as the circle turns red I want a timer which changes its color to blue after n seconds. I am not able to achieve this.

There is a section in the shapes.js file where collision between the circles is detected and thats where I am changing the colors and thats exactly where I want the timer to start. (line 104 and 110 in shapes.js file)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here is my solution to the problem you can loop it as well if you want the circle to continue changing colors (here replaced by console.log). N is here equal to seconds, it's multiplied by 1000 as setTimeout uses milliseconds by default.

   function changeColor(seconds) {
        setTimeout(function () {
                console.log('Here the circle would change color.');  
        }, seconds*1e3);
    }
    changeColor(3)
 

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