• 0

Timed loop for a timer


Question

I'm making a nifty graphical counter for days until Defcon, but can't seem to get this thing to loop more than one time. It runs, displays, then updates once before I get a damn "Object Expected" error on line 1 char 1, even when there isn't anything on that line! Irritating to say the least. Could you look at my code and see if you can figure it out? I'm attaching a zip with the html and graphics if u wanna test it out... Keep in mind that this is my first ever javascript program, so if it is something n00bish, don't flame me! :laugh:

<HTML>
<HEAD>  
<script LANGUAGE="JavaScript">
<!--;

var digitPath = "digitstore";

var digitChoice = "Y";

var digitWidth = 32;
var digitHeight = 48;

// string of digits

var digitHash = new makeArray("0","1","2","3","4","5","6","7","8","9");

// corresponding file name prefixes

var fileNameHash = new 

makeArray("zero","one","two","three","four","five","six","seven","eight","nine");

function mDays() //supposed to get number of days until defcon, gets number of milliseconds for debug purposes

{
var now = new Date();
var event = new Date("Aug 1 2003 00:00:01");
var days = (event - now);//86400000;
days = Math.round(days);
return days;
}

function update() 
{
setupDisp();
window.setTimeout("update();", 1000);
}

function emptyArray(n) // array declaration without data
{
	this.length = n;
}

function makeArray()
{
	var args = makeArray.arguments;
	for(var i = 0; i < args.length;i++) 
	{
  this[i] = args[i];
	}
	this.length = args.length;
}

// hash array that finds a filename for a digit

var xrefHash = new emptyArray(digitHash.length);

for(var i = 0;i < digitHash.length;i++) 
{
	xrefHash[digitHash[i]] = fileNameHash[i];
}

function setupDisp()
{

	var initStr = ""+mDays();
	var wh = "";
	wh = "WIDTH=" + digitWidth + " HEIGHT=" + digitHeight;
	for(var i = 0;i < initStr.length;i++) 
	{
  var fn = xrefHash[initStr.substring(i,i+1)]; // hash to filename
  var src = digitPath + "/" + digitChoice + "/" + fn + ".gif";
  document.write("<TD><IMG SRC=\"" + src + "\" NAME=\"Digit" + i
 	 + "\"" + " " + wh + "></TD>");
	}
}
update();
-->
</SCRIPT>
</HEAD>
</HTML>

defcon_countdown.zip

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

try the following code (IE only)... removes the update function. put setInterval instead. changed the writing method that did not work.

<HTML>

<HEAD>

<script LANGUAGE="JScript">

var digitPath = "digitstore";

var digitChoice = "Y";

var digitWidth = 32;

var digitHeight = 48;

// string of digits

var digitHash = new makeArray("0","1","2","3","4","5","6","7","8","9");//,":","a","p");

// corresponding file name prefixes

var fileNameHash = new

makeArray("zero","one","two","three","four","five","six","seven","eight","nine");//,"colon","am","pm");

function mDays()

{

var now = new Date();

var event = new Date("Aug 1 2003 00:00:01");

var days = (event - now);//86400000;

days = Math.round(days);

return days;

}

function emptyArray(n) // array declaration without data

{

this.length = n;

}

function makeArray()

{

var args = makeArray.arguments;

for(var i = 0; i < args.length;i++)

{

this = args;

}

this.length = args.length;

}

// hash array that finds a filename for a digit

var xrefHash = new emptyArray(digitHash.length);

for(var i = 0;i < digitHash.length;i++)

{

xrefHash[digitHash] = fileNameHash;

}

function setupDisp()

{

var initStr = ""+mDays();

var wh = "";

wh = "WIDTH=" + digitWidth + " HEIGHT=" + digitHeight;

document.body.innerHTML="";

for(var i = 0;i < initStr.length;i++)

{

var fn = xrefHash[initStr.substring(i,i+1)]; // hash to filename

var src = digitPath + "/" + digitChoice + "/" + fn + ".gif";

document.body.innerHTML+="<TD><IMG SRC=\"" + src + "\" NAME=\"Digit" + i

+ "\"" + " " + wh + "></TD>";

}

}

window.setInterval(setupDisp,1000);

</SCRIPT>

</HEAD>

<BODY></BODY>

</HTML>

Link to comment
Share on other sites

  • 0
changed the writing method that did not work.

It works! What is this, what did you change exactly, and why? Just wondering, trying to gain some insight into this new language. Thanx alot! :D

Link to comment
Share on other sites

  • 0

One more question, now that the code works, how can i align the nifty little timer to center or right side? I can't figure out where to put an align tag... I'm including the new code if u wanna play with it, or you can look at the code mdt posted above, i haven't changed much.

defcon_countdown.zip

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.