treehouse : what would you like to learn today?
Web Design Web Development iOS Development

need help....

  • I m using a script for randomly calling a text on my page using
    Math.floor(Math.random()*(quotes.length))

    this code running perfectly when i click on my page or refresh it... is that possible to autorate the quotes after sometime

    u can see the live example playbackgroup.com right panel in top box where quotes are coming
  • I'm lost. Can you define "autorate" ?
  • "AshtonSanders" said:
    I'm lost. Can you define "autorate" ?

    I think he means rotate. ie. Refresh the quote after a specified amount of time.
  • i mean refreshing a quote automatically after sometime

  • function rotateQuotes()
    {
    Math.floor(Math.random()*(quotes.length))
    setTimeout(\"rotateQuotes()\",100000);
    }




    try this let me know if this helps u
  • At the moment you are just ouputting the quote from javascript using document.write - but you can't change existing text using document.write, as it only adds contents to the page. You should really learn a DOM manipulation library like jQuery, it really makes doing this kind of thing a lot easier.

    With jQuery your function might look like the following (including cssfreaks changes):

    HTML:
    <h1>What the world thinks?</h1>
    <div id=\"quote\"></div>

    Javascript:
    function rotateQuotes() {
    var whichquote = Math.floor(Math.random()*(quotes.length));
    $('#quote').html(quotes[whichquote]);
    setTimeout(\"rotateQuotes()\",100000);
    }


    By the way you can only have one <h1> per page, so you should really change those to h2 or h3.
  • hi daves,
    i told u in my last post tht u r really a GENIUS.. :D