function foo(){
var start = 1;
var stop = 10;
if(....) {
clearTimeout(interval );
}
}
var interval = setInterval(foo, 1000 );
setTimer(1, 10);
function setTimer(c, f){
document.querySelector('#timer').innerHTML = c;
if(c < f)setTimeout(setTimer, 1000, c + 1, f);
}
setTimer(1, 10, function(){alert('finished')});
function setTimer(c, f, callback){
document.querySelector('#timer').innerHTML = c;
if(c < f)setTimeout(setTimer, 1000, c + 1, f, callback);
else if(callback)callback();
}