View Full Version : New Tip every day

10-10-2003, 09:55 PM
I have a js file on my server that contains 365 Tips. I view these tips with a javascript on my webpage. Right now the Tips are changing randomly. I want to change the server side code so that the tips change once a day for 365 days. Can anyone share the code needed to make this work? I am completely new to programming. Thanks!

10-11-2003, 05:09 AM
Are they in an array? If so, you could do something like this:

function getDateInYear(dateObj) {
var cumulative=0;
for(var i = 0; i < dateObj.getMonth(); i++) {
if(i%2==0) cumulative += 31;
else if(dateObj.getMonth()==1) {
if(dateObj.getFullYear()%4==0) cumulative += 29;
else cumulative += 28;
} else cumulative += 30;
} cumulative += dateObj.getDate();
return cumulative;
function outputTip() {
return tipArray[getDateInYear((new Date()))];

Hope that helps!

Happy coding! :)

Or better yet (since my script is a little off, by around two days I believe), use this (http://www.javascriptkit.com/script/script2/daysremaining.shtml)

10-13-2003, 03:59 PM
Thanks for the code. I assume that this code goes in my webpage and not in my external js file. I'm not quite sure how it works however. I will try to study it for understanding. Thanks!

Also can you show what the Array needs to look like so that I can make sure that mine agrees? Thanks!

Also I was confused about the edited response. I don't understand how a script that counts down to the end of the year applies. I'm just learning :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum