dianazheng
September 30th, 2004, 12:16 AM
Hi all,
i have a scipt that i want that to display a greeting message. i did some code but i am not sure whether this is right, because i can't display that out. Can anyone help me??
Thank in advance.
code
=======================
//display the greeting message
document.write("<h3><center>"+holidayMsg+" <br> </center></h3>")
//calling the greetings function
var holidayMsg = greetings()
//count the number of days from current date starting from jan
var currDay = new Date()
var currentDay = currDay.getDate()
var currentMonth = currDay.getMonth()
if(currentMonth == 1){
noOfDays = currentDay
}
if(currentMonth == 2){
noOfDays = currentDay + 31
}
if(currentMonth == 3){
noOfDays = currentDay +31 +28
}
if(currentMonth == 4){
noOfDays = currentDay +31 +28 +31
}
if(currentMonth == 5){
noOfDays = currentDay +31 +28 +31 +30
}
if(currentMonth == 6){
noOfDays = currentDay +31 +28 +31 +30 +31
}
if(currentMonth == 7){
noOfDays = currentDay +31 +28 +31 +30 +31 +30
}
if(currentMonth == 8){
noOfDays = currentDay +31 +28 +31 +30 +31 +30 +31
}
if(currentMonth == 9){
noOfDays = currentDay +31 +28 +31 +30 +31 +30 +31 +31
}
if(currentMonth == 10){
noOfDays = currentDay +31 +28 +31 +30 +31 +30 +31 +31 +30
}
if(currentMonth == 11){
noOfDays = currentDay +31 +28 +31 +30 +31 +30 +31 +31 +30 +31
}
if(currentMonth == 12){
noOfDays = currentDay +31 +28 +31 +30 +31 +30 +31 +31 +30 +31 +30
}
//function of a switch
function greetings(){
switch(month){
case 0:
if(noOfDays >= 2 && noOfDays <= 43){
daysLeft = 43 - noOfDays
document.write("Only "+daysLeft+" days untill Valentine's day!")
}
break
case 1:
if(noOfDays == 45){
document.write("Happy Valentine's Day")
}
break
case 2:
//from 15th feb to 31st aug
if(noOfDays >= 46 && noOfDays <= 243){
document.write("Please check out our current range of gifts.")
}
break
case 3:
//from 1st sept to 24th dec
if(noOfDays >= 244 && noOfDays <= 287){
daysLeft = 287 - noOfDays
document.write("Only "+daysLeft+" days left untill Christmas. ")
}
break
case 4:
// from 24th dec to 1st jan
if(noOfDays >= 358 && noOfDays <= 366){
document.write("Merry Christmas and Happy New Year ")
}
break
default:
document.write("No current event coming")
}
}
=================
code end
diana
i have a scipt that i want that to display a greeting message. i did some code but i am not sure whether this is right, because i can't display that out. Can anyone help me??
Thank in advance.
code
=======================
//display the greeting message
document.write("<h3><center>"+holidayMsg+" <br> </center></h3>")
//calling the greetings function
var holidayMsg = greetings()
//count the number of days from current date starting from jan
var currDay = new Date()
var currentDay = currDay.getDate()
var currentMonth = currDay.getMonth()
if(currentMonth == 1){
noOfDays = currentDay
}
if(currentMonth == 2){
noOfDays = currentDay + 31
}
if(currentMonth == 3){
noOfDays = currentDay +31 +28
}
if(currentMonth == 4){
noOfDays = currentDay +31 +28 +31
}
if(currentMonth == 5){
noOfDays = currentDay +31 +28 +31 +30
}
if(currentMonth == 6){
noOfDays = currentDay +31 +28 +31 +30 +31
}
if(currentMonth == 7){
noOfDays = currentDay +31 +28 +31 +30 +31 +30
}
if(currentMonth == 8){
noOfDays = currentDay +31 +28 +31 +30 +31 +30 +31
}
if(currentMonth == 9){
noOfDays = currentDay +31 +28 +31 +30 +31 +30 +31 +31
}
if(currentMonth == 10){
noOfDays = currentDay +31 +28 +31 +30 +31 +30 +31 +31 +30
}
if(currentMonth == 11){
noOfDays = currentDay +31 +28 +31 +30 +31 +30 +31 +31 +30 +31
}
if(currentMonth == 12){
noOfDays = currentDay +31 +28 +31 +30 +31 +30 +31 +31 +30 +31 +30
}
//function of a switch
function greetings(){
switch(month){
case 0:
if(noOfDays >= 2 && noOfDays <= 43){
daysLeft = 43 - noOfDays
document.write("Only "+daysLeft+" days untill Valentine's day!")
}
break
case 1:
if(noOfDays == 45){
document.write("Happy Valentine's Day")
}
break
case 2:
//from 15th feb to 31st aug
if(noOfDays >= 46 && noOfDays <= 243){
document.write("Please check out our current range of gifts.")
}
break
case 3:
//from 1st sept to 24th dec
if(noOfDays >= 244 && noOfDays <= 287){
daysLeft = 287 - noOfDays
document.write("Only "+daysLeft+" days left untill Christmas. ")
}
break
case 4:
// from 24th dec to 1st jan
if(noOfDays >= 358 && noOfDays <= 366){
document.write("Merry Christmas and Happy New Year ")
}
break
default:
document.write("No current event coming")
}
}
=================
code end
diana