LegosJedi Posted June 22, 2007 Share Posted June 22, 2007 I've created a Count-up script that starts counting and then stops at a certain number. The only problem is that when it reaches to right about that number, it just starts acting strangly. It doesn't stop, like I tell it to, and then some numbers start missing, and then some numbers are there that shouldn't be. I've run a debugging div to output what should be shown, and everything's fine in there, so It's a problem with the output. Here's my HTML and JavaScript. This problem needs to be fixed real soon, as this needs to be ready for Sunday, and I'm not going to be aroung tomorrow. <html> <head> <title>Commitment Sunday Total</title> <script src="./js.js"></script> </head> <body> <h1 id="count">000000</h1> <input type="button" value="Start!" onclick="increase(); return false;" /> <div id="debug" style="overflow: auto; height: 300px; width: 300px;"></div> </body> </html> var end = '123400'; var speed = 1; // 100 is slowest, 1 is fastest var timer = ""; var hundreds = '0'; var thousands = '0'; var tenthousands = '0'; var hundredthousand = '0'; function increase() { hundreds++; if(hundreds == '10') { hundreds = '0'; thousands++; } if(thousands == '10') { thousands = '0'; tenthousands++; } if(tenthousands == '10') { tenthousands = '0'; hundredthousand++; } current = hundredthousand+tenthousands+thousands+hundreds+'00'; count = document.getElementById('count'); count.innerHTML = current; if(current != end) { if(hundredthousand == end.substr(0, 1)) { document.getElementById('debug').innerHTML = document.getElementById('debug').innerHTML+'<br />'+hundredthousand+tenthousands+thousands+hundreds+'00'; var timer = setTimeout('increase()', 50*speed); } else { var timer = setTimeout('increase()', 10*speed); } } else { clearTimeout(timer); } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.