Results 1 to 8 of 8

Thread: Random quote script

  1. #1
    Join Date
    Apr 2005
    Posts
    49
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Random quote script

    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

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Apr 2005
    Posts
    49
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    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

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Apr 2005
    Posts
    49
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks Twey

    will give a try see how it goes


  6. #6
    Join Date
    Oct 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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?

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Jul 2005
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I know this is kind of late, but the Ajax Rotating Include Script 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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •