how to get quotes to coninually refresh from js variable array?

Discussion in 'JavaScript' started by truther, Oct 28, 2007.

  1. #1
    // random quotes function
    var quotes = [""How many legs does a dog have if you call the tail a leg? Four; calling a tail a leg doesn't make it a leg." - A.Lincoln", ""Truth is generally the best vindication against slander." - A.Lincoln" , ""You can fool some of the people all of the time, and all of the people some of the time, but you can not fool all of the people all of the time." - A.Lincoln"];
    
    function getRandomQuote(){
    numberOfQuotes = quotes.length;
    randNum = Math.floor(Math.random()*numberOfQuotes);
    return quotes[randNum];
    }
    Code (markup):
    Don't know js to save my arse, but was wondering if there might be a continuous loop for refreshing the quote array, say, every 6 seconds?

    Gracias para la ayuda!
     
    truther, Oct 28, 2007 IP
  2. dpfreaks

    dpfreaks Peon

    Messages:
    37
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    call this function

    setInterval("getRandomQuote()",6000);

    out side of your function for example:


    <script language="javascript">
    // random quotes function
    var quotes = ["&quot;How many legs does a dog have if you call the tail a leg? Four; calling a tail a leg doesn't make it a leg.&quot; - A.Lincoln", "&quot;Truth is generally the best vindication against slander.&quot; - A.Lincoln" , "&quot;You can fool some of the people all of the time, and all of the people some of the time, but you can not fool all of the people all of the time.&quot; - A.Lincoln"];
    
    function getRandomQuote(){
    numberOfQuotes = quotes.length;
    randNum = Math.floor(Math.random()*numberOfQuotes);
    alert(quotes[randNum]);
    }
    setInterval("getRandomQuote()",6000);
    </script>
    Code (markup):
     
    dpfreaks, Oct 29, 2007 IP