1

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
2
  • 1
    It's not 600000 but 60000. Commented Oct 30, 2012 at 13:30
  • 2
    thinking about actually waiting 10 min made me laugh. Commented Oct 30, 2012 at 13:31

5 Answers 5

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

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)
1

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

Comments

1

60 seconds = 60000 ms not 600000

answered Oct 30, 2012 at 13:31

Comments

0

600000 isn't one minute...

setInterval is in milliseconds.

answered Oct 30, 2012 at 13:31

Comments

0

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.