I have a simple setTimeout function that runs at a specific time and works fine:
var now = new Date();
var milliTillExec = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes(), 0, 0) - now;
if (milliTillExec < 59500) {
milliTillExec += 59500;
}
window.setTimeout(function(){
console.log('at 59:500');
},milliTillExec);
trying to add a function that runs every 300 milliseconds after the previous function fired, so I did like this :
function runEvery300Milli(){
var t = new Date();
window.setInterval(function(){
if((t.getMinutes===59 && t.getMilliseconds>499)||(t.getMinutes===0 && t.getMilliseconds<500)){
console.log(t.getMinutes()+ ":"+t.getSeconds() + ":"+ t.getMilliseconds());
}
}, 300)();
}
var now = new Date();
var milliTillExec = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes(), 0, 0) - now;
if (milliTillExec < 59500) {
milliTillExec += 59500;
}
window.setTimeout(function(){
console.log('at 59:500');
runEvery300Milli();
},milliTillExec);
but I get the following error:
Uncaught TypeError: setInterval(...) is not a function
at runEvery300Milli
setInterval(fn, 300)()... since setInterval returnsundefined, this is what is not a function - setInterval is, but what it returns is not - simply remove the()after, 300)Demo,