PDA

View Full Version : Random quote script



QuizToon
09-21-2005, 05:20 PM
I have a script which generates a fresh quote each time the page is refreshed. Is there a script that does the same thing but only on a new day, EG a script for quote of the day instead of on each refresh.

I am pretty new to javascript so any answers would need to be idiot proof for me :)

Thanks in advance

Twey
09-21-2005, 05:38 PM
Just base the random number on the day of the month (Date.getDate()). If you want to post the script here, I'll tell you how.

QuizToon
09-21-2005, 05:46 PM
Hi there

Here is the script i am working with. I have deleted a lot of the quotes to save space in here.


<script language="JavaScript">
var Quotation=new Array() // do not change this!

Quotation[0] = "Time is of the essence! Comb your hair.";
Quotation[1] = "Sanity is a golden apple with no shoelaces.";
Quotation[2] = "Repent! The end is coming, $9.95 at Amazon.";
Quotation[3] = "Honesty blurts where deception sneezes.";
Quotation[4] = "Pastry satisfies where art is unavailable.";
Quotation[5] = "Delete not, lest you, too, be deleted.";

// ======================================
// Do not change anything below this line
// ======================================
var Q = Quotation.length;
var whichQuotation=Math.round(Math.random()*(Q-1));
function showQuotation(){document.write(Quotation[whichQuotation]);}
showQuotation();
</script>

Thanks for your help

Twey
09-21-2005, 05:52 PM
<script language="JavaScript">
var Quotation=new Array() // do not change this!

Quotation[0] = "Time is of the essence! Comb your hair.";
Quotation[1] = "Sanity is a golden apple with no shoelaces.";
Quotation[2] = "Repent! The end is coming, $9.95 at Amazon.";
Quotation[3] = "Honesty blurts where deception sneezes.";
Quotation[4] = "Pastry satisfies where art is unavailable.";
Quotation[5] = "Delete not, lest you, too, be deleted.";

// ======================================
// Do not change anything below this line
// ======================================
var today = new Date();
today = today.getDate();
var Q = Quotation.length;
var whichQuotation=Math.round(Math.random(today)*(Q-1));
function showQuotation(){document.write(Quotation[whichQuotation]);}
showQuotation();
</script>
This will base the random number on the day of the month, meaning that until the day changes, the same "random" number will keep being generated.

QuizToon
09-21-2005, 06:01 PM
Thanks Twey

will give a try see how it goes

:)

googlefreak
10-19-2005, 02:48 AM
Do we change the quote database file each month if we do not want it to start all over again -- or is there a way to make that part into the script too?

Twey
10-19-2005, 03:22 PM
It will select a random quote every day. If you wanted to do a set order, try something like:

<script type="text/javascript">
var Quotation=new Array() // do not change this!

Quotation[0] = "Time is of the essence! Comb your hair.";
Quotation[1] = "Sanity is a golden apple with no shoelaces.";
Quotation[2] = "Repent! The end is coming, $9.95 at Amazon.";
Quotation[3] = "Honesty blurts where deception sneezes.";
Quotation[4] = "Pastry satisfies where art is unavailable.";
Quotation[5] = "Delete not, lest you, too, be deleted.";
// You need 26 more quotes here - the script will throw a
// tantrum if it reaches a day for which there is no quote.

// ======================================
// Do not change anything below this line
// ======================================
var today = new Date();
today = today.getDate();
var Q = Quotation.length;
function showQuotation(){document.write(Quotation[today]);}
showQuotation();
</script>
If you really want to create a year's worth of quotes at a time, you can; but the massive array might slow down some browsers on machines with less RAM.

anonymouse
11-07-2005, 04:56 PM
I know this is kind of late, but the Ajax Rotating Include Script (http://www.dynamicdrive.com/dynamicindex17/ajaxrotate.htm) is set up to do a month's worth of this. Only thing is it looks like each quote would have to be a separate file. Just an option, that's all.