I am trying to fire a function every 60 seconds.
Here is my current code:
<script>
$(document).ready(function() {
setInterval(alertme, 600000);
});
function alertme() {
alert('1 minute has passed');
}
</script>
For some reason the function alertme is not being called.
Any ideas why?
asked Oct 30, 2012 at 13:29
Satch3000
49.7k90 gold badges225 silver badges349 bronze badges
5 Answers 5
Interval parameter in the setInterval function is in milliseconds.
So 1 minute = 60 sec = 60 * 1000 millisec = 60000 millisec
answered Oct 30, 2012 at 13:30
Alberto De Caro
5,2139 gold badges51 silver badges77 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Jasper
You're giving what it should be, but you are forgetting to mention that it isn't what it currently is (with the only difference being the number of zeroes, it's easy to miss)
There are 1,000ms in a second, not 10,000. This will fire after 10 minutes, not 1.
answered Oct 30, 2012 at 13:31
Quentin
949k137 gold badges1.3k silver badges1.4k bronze badges
Comments
60 seconds = 60000 ms not 600000
answered Oct 30, 2012 at 13:31
Marcos
4,6637 gold badges35 silver badges62 bronze badges
Comments
600000 isn't one minute...
setInterval is in milliseconds.
answered Oct 30, 2012 at 13:31
Dave Hogan
3,2216 gold badges32 silver badges56 bronze badges
Comments
Here is correct code:
<script>
$(document).ready(function() {
setInterval(alertme, 60000);
});
function alertme() {
alert('1 minute has passed');
}
</script>
answered Oct 30, 2012 at 13:35
Zaheer Ahmed
28.7k12 gold badges77 silver badges113 bronze badges
Comments
lang-js
600000but60000.