Jump to content

Countup Problem


LegosJedi

Recommended Posts

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);
}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.