Question: I'm aware of both `setInterval` and `setTimeout` functions but it's not suitable for my case, because I need to create an `img` DOM element in the interval of 7 seconds.

* The count of images are not predefined (varies daily).

When I use `setInterval`, I cannot *completely* stop it after certain limit (daily count). [`clearInterval` clears iterations only] 

When I use `setTimeout` inside loop (daily count), it never delays. So the only possibility is a sleep function. Can anyone help for this situation?

* What's the best way to implement a sleep function JavaScript?

Answer: 
This is quite simple and also has been answered before. See the answers to this question: 

* [Want a javascript function to run every minute, but max 3 times.](https://stackoverflow.com/questions/1245617/want-a-javascript-function-to-run-every-minute-but-max-3-times)
You're complaining about setTimeout and setInterval, but then describing how you are using them badly. Either user setTimeout **not in a loop** and have it call another setTimeout if there is more to do, or use setInterval and call clearInterval after a maintained count is reached.