Forum Moderators: open

Message Too Old, No Replies

Help with random script

How do I do this

         

ogletree

5:30 pm on Jun 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have a good script that is in the onload of the body tag. It runs great and gives me a random quote every time the page loads. What I need is for the random quote to be changed once every 3 days. I would like it to keep what it got on the fisrt day and keep that for 3 days. If it is easirer I can do it every other day so I can just look at the date and determine odd or even.

Bernard Marx

6:15 pm on Jun 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



function getPeriodicQuote()
{
// ...............parameters
var daysInPeriod = 3
var quotes =
[
"you can test this by changing *startDay*",
"decreasing the number will..",
"..move forward in time",
"Today is 12593",
"Don't go higher than that (today)",
"ANY other number will be OK",
"Amend the order of quotes",
"..instead of getting the day right"// no comma
]
// ...............constants
var msInADay = 86400000
var startDay = 12590
// .......................
var millisecs = new Date().getTime()

var daysSinceStart = Math.floor(millisecs/msInADay) - startDay
var no_periods = Math.floor(daysSinceStart/daysInPeriod)
var quoteIndex = no_periods % quotes.length
return quotes[quoteIndex]
}