Log In · Register

 
If ever there was a time of dire need..., Well, now wouldn't be it. -shrug-
talcumpowder
post May 13 2006, 03:13 PM
Post #1


You'll find me in your dreams.
*******

Group: Official Member
Posts: 8,536
Joined: Mar 2005
Member No: 114,010



Wanna help Reili do her homework? Okay.
[ http://www.blewmyallowanceonmanga.net/ribb...ssigned/npn.htm ]
Now, explain why my Javascript isn't working. Please.
CODE
<script type="text/javascript">
    <!-- hiding from non-javascript browsers
    var Today=new Date("October 15, 2006");
    var ThisDay=Today.getDate();
    var ThisMonth=Today.getMonth()+1;
    var ThisYear=Today.getFullYear();
    var DaysLeft=XmasDays(Today);

  document.write("Today is "+ ThisMonth +"/"+ ThisDay  +"/"+ ThisYear +"<br />");
if (DaysLeft > 0) {
  document.write("Only "+ DaysLeft +" left until Christmas!");
}

else {
  document.write("Happy Holidays from North Pole Novelties!");
}
    // stop hiding -->
</script>
^ That's in the HTML file. Then there's library.js:
CODE
/* Function: XmasDays()
   Purpose: Calcute difference between Christmas& a given date.

Variables:
   CheckDay: A date object containing the given date.
   XYear: The four-digit year value of the given date.
   XDay: December 25 in the year of the given date.
   DayCount: The number of days between Christmas and the given date.
*/

function XmasDays(CheckDay) {
    var XYear=CheckDay.getFullYear();
    var XDay=new date("December 25, 2006");
    XDay.setFullYear(XYear);
    var DayCount=(XDay-CheckDay)/(1000*60*60*24);
    DayCount=Math.round(DayCount);
    return DayCount;
}
Before I added the above function and the following section of code:
CODE
if (DaysLeft > 0) {
  document.write("Only "+ DaysLeft +" left until Christmas!");
}

else {
  document.write("Happy Holidays from North Pole Novelties!");
}
It worked. So I'm guessing I screwed up royally somewhere and I just don't see it. Or the book I was working out of screwed up. Either way.

To get really technical, I know what the problem is. Something, something "XmasDays not defined"&something, something "Date not defined". Translate?
 
 
Start new topic
Replies (1 - 2)
*mipadi*
post May 18 2006, 08:24 AM
Post #2





Guest






Well, one thing I can suggest is that, as far as I know, you can't use the Date() method that way. Date() always returns the current date, no matter what parameter is passed. You have to use setDate(), setMonth(), and setFullYear() to change it.
 
talcumpowder
post May 18 2006, 08:27 PM
Post #3


You'll find me in your dreams.
*******

Group: Official Member
Posts: 8,536
Joined: Mar 2005
Member No: 114,010



Err.... Yeah... All I was doing was coping outta my book. Like, straight outta the book. It said to do that so I did.
And I know it works. That's not the problem. The problem is it only seems to work on one computer and for one person. My teacher. Whenever I fix my problems... They don't really fix anything. Then he does it on his computer and POOF! Everything's all better. >.<" What kind of crazy code is this?! T.T
 

Closed TopicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members: