Javascript problem not sure what this would be called

K

Kevin Duggan

Here is the URL of my page:

http://www.kevsblues.com/CATER/din.html

________________________________________

I can not understand how to get this so the page
reads "Only 9 days till Thanksgiving"
or whatever the date may be. (Xmass ect....)

I could not get this to work
so I put the

"Leave the Party to KevsBlues Catering"

I have a funny feeling there may lie the problem...

But

any help please

Thanks

Kevin

______________________________________





var holidayCntMsg = "Leave the party to KEVSBLues Catering"
var curDay = new Date()
var tMonth = curDay.getMonth()
function HolidayDays() {
switch (tMonth) {
case 2:
var tHoliday = new Date("March 17, 2001")
var curHoliday = tHoliday.getTime()-curDay.getTime()
if (curHoliday > 0) {
curHoliday = Math.ceil(curHoliday / (1000*60*60*24))
holidayCntMsg = "Only " +curHoliday+ " days until St. Patrick's Day!"
}
break
case 6:
var tHoliday = new Date("July 4, 2001")
var curHoliday = tHoliday.getTime()-curDay.getTime()
if (curHoliday > 0) {
curHoliday = Math.ceil(curHoliday / (1000*60*60*24))
holidayCntMsg = "Only " +curHoliday+ " days until the 4<sup>th</sup> of July!"
}
break
case 9:
var tHoliday = new Date("October 31, 2001")
var curHoliday = tHoliday.getTime()-curDay.getTime()
if (curHoliday > 0) {
curHoliday = Math.ceil(curHoliday / (1000*60*60*24))
holidayCntMsg = "Only " +curHoliday+ " days until Halloween!"
}
break
case 10:
var tHoliday = new Date("November 22, 2001")
var curHoliday = tHoliday.getTime()-curDay.getTime()
if (curHoliday > 0) {
curHoliday = Math.ceil(curHoliday / (1000*60*60*24))
holidayCntMsg = "Only " +curHoliday+ " days until Thanksgiving!"
}
break
case 11:
var tHoliday = new Date("December 25, 2001")
var curHoliday = tHoliday.getTime()-curDay.getTime()
if (curHoliday > 0) {
curHoliday = Math.ceil(curHoliday / (1000*60*60*24))
holidayCntMsg = "Only " +curHoliday+ " days til CHRISTMAS!"
}
break
}
return holidayCntMsg
}
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Mon, 6 Sep 2004
20:49:39, seen in Lee
Kevin Duggan said:

Change all your dates from 2001 to 2004.

How will that help for St Patrick's Day and US Independence Day? The
November date will need to be recalculated, too.
 
D

Dr John Stockton

JRS: In article <060920042237321039%[email protected]>, dated
Tue, 7 Sep 2004 02:33:06, seen in Kevin
Duggan said:
I can not understand how to get this so the page
reads "Only 9 days till Thanksgiving"
or whatever the date may be. (Xmass ect....)
ect?


var holidayCntMsg = "Leave the party to KEVSBLues Catering"
var curDay = new Date()
var tMonth = curDay.getMonth()
function HolidayDays() {
switch (tMonth) {
case 2:
var tHoliday = new Date("March 17, 2001")
var curHoliday = tHoliday.getTime()-curDay.getTime()
if (curHoliday > 0) {
curHoliday = Math.ceil(curHoliday /
(1000*60*60*24))
holidayCntMsg = "Only " +curHoliday+ " days
until St. Patrick's Day!"
}
break

case 11:
var tHoliday = new Date("December 25, 2001")
var curHoliday = tHoliday.getTime()-curDay.getTime()
if (curHoliday > 0) {
curHoliday = Math.ceil(curHoliday /
(1000*60*60*24))
holidayCntMsg = "Only " +curHoliday+ " days til
CHRISTMAS!"
}
break
}
return holidayCntMsg
}


Code posted to News should not be machine-wrapped. The author should
deal with that, rather than forcing it on his possible readers, who
generally will not want to bother.

In News, an 8-space tab is too much indentation.

Your code is repetitive; use a single function, and call it for each
case.

You need to get the year right, and to calculate the November date
accordingly.

Your day-count will change at midnight, or an hour earlier or later,
depending on the state of Summer Time at the user's location on the
current and cited date; that's inelegant. Code containing 1000*60*60*24
is always suspect, though not necessarily wrong. You can do setHours(0)
on today's date, then Math.round() on the difference (unchecked).


Given that you only show a holiday (and St.P is not AFAIK a holiday
anywhere that celebrates 04-07) once its month is started, it would be
simpler just to subtract the day-of-month.

What's UML? Lansing??

Read the newsgroup FAQ before posting, and you will often be led to the
methods you need.
 
K

Kevin Duggan

Code posted to News should not be machine-wrapped. The author should
deal with that, rather than forcing it on his possible readers, who
generally will not want to bother.

In News, an 8-space tab is too much indentation.


Sorry about that thanks for the information
Your code is repetitive; use a single function, and call it for each
case.

You need to get the year right, and to calculate the November date
accordingly.

I know, I am just trying to get this to work
changing the date is easy enough

Your day-count will change at midnight, or an hour earlier or later,
depending on the state of Summer Time at the user's location on the
current and cited date; that's inelegant. Code containing 1000*60*60*24
is always suspect, though not necessarily wrong. You can do setHours(0)
on today's date, then Math.round() on the difference (unchecked).


Given that you only show a holiday (and St.P is not AFAIK a holiday
anywhere that celebrates 04-07) once its month is started, it would be
simpler just to subtract the day-of-month.

What's UML? Lansing??


U Mass Lowell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top