if(coord.left < halftBlock) { var l = setInterval(timerLeft); } else { var r = setInterval(timerRight); } function timerLeft() { //...my code clearInterval(l); } function timerRight() { //...my code clearInterval(r); }