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

217
Views
If I have multiple divs on my screen, and on click they all move to the right of the webpage. How can I determine which reached first?

I have a parent class of animal and multiple subclasses like, leopard, caracal and cheetah. They are placed on the web page once their respective buttons are clicked and when my button start is clicked, they all move at random times (milliseconds) to the right of the webpage. How would I determine which one was the first to arrive at the right of the page?

This is how I get the full width of the web page:

var trackWidth = $(window).width();

The function bellow is invoked one the start button on the html page is clicked, every child class or animal in this case has this function

Leopard.prototype.getReady = function() {
var raceTime = Math.floor((Math.random() * 5000) + 1)
this.$node.animate({
    left: trackWidth,//This move the animal the width of the webpage(In this case, the track)
}, raceTime)
}

This is an array that stores each instance of an Animal:

var arr = window.animals = [];

This function iterates through the array and calls the getReady of each child class

 var start_btn = document.querySelector(".startRace");
    $(start_btn).click(function() {
        arr.forEach(function(animal) {
            animal.getReady()
        })
    })

So yes, my question is if four animals were racing across the width of the webpage, how would I be able to print which one was first or has one the race?

(Please inform me if the question needs to be updated or redone)

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!