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

202
Views
Change the method of array for start and stop timing to sequently

I just need to change the method of array to sequently for start and stop timing. I need to be like this :

start"word1, "start"word2", start"word3", start"word4"

const timings = [
  { start: 0, stop: 1000 },
  { start: 1000, stop: 2000 },
  { start: 2000, stop: 5000 },
  { start: 5000, stop: 10000 }
]

const durations = timings.map(timing => timing.stop - timing.start                             
)

const container = document.body;
const childArray = [...container.children]; // To use array methods


childArray.forEach((el, i) => {
  el.onclick = () => {
    el.classList.toggle('highlight');
    
    nextWord = childArray[i + 1];
    if (!nextWord) return // Last word
    
    setTimeout(() => {
      el.classList.toggle('highlight');
      nextWord.click();
    }, durations[i])
  }
})
.highlight {
  background-color: yellow;
}
<!DOCTYPE html>
<html>
<body>
  <span>word1</span>
  <span>word2</span>
  <span>word3</span>
  <span>word4</span>
</body>
</html>

about 4 years ago · Santiago Gelvez
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!