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>
Question
Antipop
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