How do I add a delay in a JavaScript loop? - From https://stackoverflow.com/questions/3583724/how-do-i-add-a-delay-in-a-javascript-loop
(function myLoop (i) {
setTimeout(function () {
alert('hello'); // your code here
if (--i) myLoop(i); // decrement i and call myLoop again if i > 0
}, 3000)
})(10); // pass the number of iterations as an argument