setInterval(function(){
// code
}, 1000);
(function loop() {
setTimeout(function () {
// execute script
loop()
}, 9000); //9000 = 9000ms = 9s
}());
setInterval(function(){
//this code runs every second
}, 1000);
var time = 1;
var interval = setInterval(function() {
if (time <= 3) {
alert(time);
time++;
}
else {
clearInterval(interval);
}
}, 5000);