tags:

views:

130

answers:

3

I keep getting a "Undefined function" JavaScript error in my error console. Any idea why?

<div id="counter" style="width: 40px;"></div>

<script type="text/javascript">
    var seconds = 60
    document.getElementById('counter').innerHTML = seconds

    function countDown() {
     if(seconds <= -1) {
      seconds += 1
     } else {
      seconds -= 1
      document.getElementById('counter').innerHTML = seconds
      setTimeout("countDown()", 1000)
     }
    }

    countDown();
</script>
+1  A: 

You may want to consider adding some semicolons;

clownbaby
Semicolons were made optional in JavaScript 1.5.
ephemient
A: 

The undefined function may be document.getElementById if you execute this piece of code before the document is loaded. But I could be wrong.

Fabien Ménager
A: 

It stops at -1 for me which is what you have at your 'if' statement.

Tereno