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

247
Views
How to fix setTimeout() when appending to document

So I have a thing to show when a user is typing in my website but I want the typing... to show the dots slower rather than instantly right now I have my current code which works perfectly which is great just it sends the .. and turns it into ... instantly but I'd like to add a like timeout somehow.

var countTyping = 0;

function typingAnimation() {
let items = ['.', '..', '...'];
//return items[Math.floor(Math.random() * items.length)];
//return items[countTyping]; dont use
if (countTyping < 2) {//if the count is less than 2
  countTyping++
  return items[countTyping]
}
  else {
    countTyping = 0
    return items[countTyping];
  }
}

later on I have

'user is typing' + typingAnimation()

in my code which is appended to the document so I can't use a setTimeout(typingAnimation, 1000) or anything or it would show random numbers.

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

0

My fix was to add more elements to the array but there are lot more options but this is easiest and quick find for me.

let items = ['.', '.', '..', '..', '...', '...'];
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!