Jump to content

Xmas count down script isn't working!


clonetrooper9494

Recommended Posts

I made a Christmas count down script, it displays the milliseconds until Christmas :):mellow: and I tried to add Seconds, Minutes, and Hours, but the script stopped working! It just says 'Error: Object Expected' on line 98 (around the 'body onload=all()' part). I have looked at the scrupt, but I have no clue why it stopped. The code is below, or go to http://free.hostultra.com/~clonetrooper/Xmas.html ...

<html><head><title>The Ultimate Christmas Count-Down</title><script type="text/javascript">//Made by **********//Feel free to use this script, but please leave in these lines!//Big thanks to [url="http://w3schools.com/"]http://w3schools.com/[/url] and [url="http://jsmadeeasy.com/"]http://jsmadeeasy.com/[/url]//*************************************************function a(){var a = new Date();var bb = a.getYear();var c = new Date("December 25, " + bb);var d = c.getTime() - a.getTime();var e = Math.floor(d / (1000 * 60 * 60 * 24));var f = e + 1;var g = c.getMilliseconds();var h = new Date();var i = h.getHours();var j = h.getMinutes();var k = h.getSeconds();var l =i * 3600000;var m = j * 60 * 1000;var n = k * 1000;var o = l + m + n;var p = h.getMilliseconds();var q = p + o + g;var r = 86400000 * f;var s = r - q;document.getElementById('div1').innerHTML = s;var time = setTimeout('a()',150);}//*************************************************function b(){var a = new Date();var bb = a.getYear();var c = new Date("December 25, " + bb);var d = c.getTime() - a.getTime();var e = Math.floor(d / (1000 * 60 * 60 * 24));var f = e + 1;var g = c.getMilliseconds();var h = new Date();var i = h.getHours();var j = h.getMinutes();var k = h.getSeconds();var l =i * 3600;var m = j * 60;var n = k;var o = l + m + n;var p = h.getMilliseconds();var q = p + o + g;var r = 86400000 * f;var s = r - q;document.getElementById('div2').innerHTML = q + " / 86400000 of the day.;var time = setTimeout('b()',150);}//*************************************************function c(){var a = new Date();var bb = a.getYear();var c = new Date("December 25, " + bb);var d = c.getTime() - a.getTime();var e = Math.floor(d / (1000 * 60 * 60 * 24));var f = e + 1;var g = c.getSeconds();var h = new Date();var i = h.getHours();var j = h.getMinutes();var k = h.getSeconds();var l =i * 3600;var m = j * 60;var n = k;var o = l + m + n;var p = h.getSeconds();var q = p + o + g;var r = 86400 * f;var s = r - q;document.getElementById('div3').innerHTML = s;var time = setTimeout('c()',150);}//*************************************************//*************************************************//*************************************************function all(){a();b();c();}</script></head><body onload="all()"><div id="div1">You do not support JavaSrcipt!!</div><div id="div2">You do not support JavaSrcipt!!</div><div id="div3">You do not support JavaSrcipt!!</div><div id="div4">You do not support JavaSrcipt!!</div><div id="div5">You do not support JavaSrcipt!!</div><div id="div6">You do not support JavaSrcipt!!</div><br>Test...</body></html>

If you see any problems, please tell me, (gotta get it done befor Christmas! :) )

Link to comment
Share on other sites

I made one myself, maybe you can try to play with it to get it to your liking.

<script type="text/javascript">  function countdown() {    var div=document.getElementById("countdown");      div.innerHTML="";    var today=new Date();    var christmas=new Date("December 25, "+(today.getYear()+1900));    var today_info=new Array();      today_info[0]=today.getMonth()+1;      today_info[1]=today.getDate();      today_info[2]=today.getHours()+1;      today_info[3]=today.getMinutes();      today_info[4]=today.getSeconds();    var christmas_info=new Array();      christmas_info[0]=christmas.getMonth()+1;      christmas_info[1]=christmas.getDate()-1;      christmas_info[2]=24;      christmas_info[3]=60;      christmas_info[4]=60;    var t=new Array();      t[0]="Months";      t[1]="Days";      t[2]="Hours";      t[3]="Minutes";      t[4]="Seconds";    var sub;    for (var i=0; i<today_info.length; i++) {      sub=christmas_info[i]-today_info[i];      if (sub==christmas_info[i] || sub<0) {        sub=0;      }      if (t[i]=="Days" && sub==0) {        div.innerHTML="Merry Christmas!";        break;      }      div.innerHTML+=sub+" "+t[i]+" ";      if (today_info.length-1==i) {        div.innerHTML+="until Christmas!";      }    }    setTimeout("countdown()", 1000);  }  window.onload=countdown;</script><div id="countdown"></div>

Link to comment
Share on other sites

Well, I think the problem is having var's a; b; and c all in one function, and then again in another, so when they both get called from 'all' function, the var's get all jumbled. I will use yours as a last resort if my new idea's don't work...thanks anyways though!

Link to comment
Share on other sites

When using variables outside of functions, they are global in scope meaning they can be used anywhere. If they are in functions, they will only be set in that one function, and that's it.There are some bugs in my code that will need to be fixed, such as it saying Merry Christmas on December 24 and after.

Link to comment
Share on other sites

Geez, surely you can think of better variable names then letters. That makes it a little difficult to follow the code, always use descriptive variable names if you can. The problem is probably that you have functions called a, b, and c but in each one you have variables with the same name. It's not a great idea to make a local variable with the same name of the function that it's inside.

Link to comment
Share on other sites

Sorry abotu that... I tried to shorten the code, because the var's names were LONG!I changed the vars back, and I changed the function names, and... IT WORKS!!! Thanks every one!(Off to the HTML boards! stupid div...)http://free.hostultra.com/~clonetrooper/Xmas.html

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...