Time base events

[LEFT]Hi,
New here. I was just wondering whether it was possible to perform a function after a period of time.like +2 to hp every 6 seconds
Any help appriciated
[/LEFT]

function increaseHP() {
     hp +=2;
}

//use this command to start increasing
hpInt = setInterval(increaseHP, 6000); // in miliseconds

// use this command to stop increasing
clearInterval(hpInt);

thanks!!!