1

I want to add a little interaction on a page that acts kind of like a very simple bot.

How can I simulate a little time delay like you see in bots? (when it shows a 'typing...' indicator or that image with dots that animates).

Rikin
  • 5,121
  • 2
  • 14
  • 22
cool breeze
  • 4,131
  • 5
  • 34
  • 60
  • 4
    Have you tried using `setTimeout`? – Carcigenicate Oct 04 '19 at 21:38
  • This question is sort of on the cusp of being too broad... but a using [`setTimeout`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout) with a random interval would be my starting point. – Alexander Nied Oct 04 '19 at 21:40
  • Possible duplicate of [Put a Delay in Javascript](https://stackoverflow.com/questions/1183872/put-a-delay-in-javascript) – jonny Oct 04 '19 at 21:40
  • Add element with css style of loading svg with animation, then use setTimeout after which you remove the svg loading element and append the answer. – Олег Якунин Oct 04 '19 at 21:40
  • you don't need `settimeout` just display 3 dots animation, at the begining of the method, then when the bot is finished removed the dots from the UI. – Train Oct 04 '19 at 21:44

1 Answers1

0

You can use setTimeout like below.

startDelay = (timeDelay) => {
  console.log(`It's time to go`);
  setTimeout(() => {
     console.log('I wake up');
  }, timeDelay);
};

startDelay(3000);
John Montgomery
  • 6,346
  • 8
  • 51
  • 63
Diamond
  • 3,146
  • 1
  • 17
  • 36