Random Quotes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Brigitte Behrmann
    New Member
    • Jun 2007
    • 25

    Random Quotes

    Please can some-one help, I cannot get this to work.
    Code:
    <html>
    <head>
    <title>Random Proverbs</title>
    <script type="text/javascript">
    <!-- HIDE FROM INCOMPATIBLE BROWSERS
    function changeQuote() {
         var quotes = new array()
         quotes[0] = "Laughter is the best medicine";
         quotes[1] = "Never look a gift horse in the mouth";
         quotes[2] = One good turn deserves another";
         quotes[3] = "The early bird catches the worm";
         quotes[4] = "Two is company, three is a crowd";
         var newQuote = quotes[Math.round(Math.random()+quotes.length)];
         document.quoteform.quote.value = newQuote[0];
    }
    var tick = setInterval("changeQuote()",3000);
    //STOP HIDING FROM INCOMPATIBLE BROWSERS -->
    </script>
    </head>
    <body>
    <form action="">
    <input type="text" size="50" name="quote" /><br/>
    </form>
    </body>
    </html>
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    hi ...

    have a close look at the following (working) version of your code:

    [HTML]<html>
    <head>
    <title>Random Proverbs</title>
    <script type="text/javascript">
    <!-- HIDE FROM INCOMPATIBLE BROWSERS
    function changeQuote() {
    var quotes = new Array()
    quotes[0] = "Laughter is the best medicine";
    quotes[1] = "Never look a gift horse in the mouth";
    quotes[2] = "One good turn deserves another";
    quotes[3] = "The early bird catches the worm";
    quotes[4] = "Two is company, three is a crowd";

    var newQuote = quotes[Math.round(Math .random()*(quot es.length-1))];
    document.quotef orm.quote.value = newQuote;
    }
    var tick = setInterval("ch angeQuote()",30 00);
    //STOP HIDING FROM INCOMPATIBLE BROWSERS -->
    </script>
    </head>
    <body>
    <form name="quoteform " action="">
    <input type="text" size="50" name="quote" /><br/>
    </form>
    </body>
    </html>
    [/HTML]

    you missed the name of the form, the rnd-number was wrong, newQuote is the array-value already, new Array()! (you may use [] for that) ... testing your script in firefox with the firebug-extension shows you most of the errors ...

    kind regards ...

    Comment

    • Brigitte Behrmann
      New Member
      • Jun 2007
      • 25

      #3
      Originally posted by gits
      hi ...

      have a close look at the following (working) version of your code:

      [HTML]<html>
      <head>
      <title>Random Proverbs</title>
      <script type="text/javascript">
      <!-- HIDE FROM INCOMPATIBLE BROWSERS
      function changeQuote() {
      var quotes = new Array()
      quotes[0] = "Laughter is the best medicine";
      quotes[1] = "Never look a gift horse in the mouth";
      quotes[2] = "One good turn deserves another";
      quotes[3] = "The early bird catches the worm";
      quotes[4] = "Two is company, three is a crowd";

      var newQuote = quotes[Math.round(Math .random()*(quot es.length-1))];
      document.quotef orm.quote.value = newQuote;
      }
      var tick = setInterval("ch angeQuote()",30 00);
      //STOP HIDING FROM INCOMPATIBLE BROWSERS -->
      </script>
      </head>
      <body>
      <form name="quoteform " action="">
      <input type="text" size="50" name="quote" /><br/>
      </form>
      </body>
      </html>
      [/HTML]

      you missed the name of the form, the rnd-number was wrong, newQuote is the array-value already, new Array()! (you may use [] for that) ... testing your script in firefox with the firebug-extension shows you most of the errors ...

      kind regards ...
      Will do, thanks so much for the help, you have no idea how lost and frustrated I feel.
      I found a download for Firefox, but have no idea how it works. Any tips as the help guide does not explain how to test one's code! ..... now I really sound doff, but this is all very new to me!

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        ... firefox is a webbrowser based on the gecko-rendering-engine that is also used by netscape, mozilla, ... browsers. simply install it and use it like ms internet explorer ... it is nearly the same ... there is nothing more to mention about it ... you will see.

        firefox is 'extensible' that means there are some extensions (consider it as kind of plugins) that you may download and install to it ... so go to firefox's menu and go to 'extras' -> 'add-ons' - a popup appears. you click 'extensions' on top of it ... and then you click 'download extensions' (right bottom corner) ... you will be directed to the extensions-download-page ... search for firebug and use the install-link provioded there ... that installs firebug ... and next time you start firefox you notice a little symbol in the right bottom corner of it ... click it and enable firebug ... you will see what to do! ... then load a page with your script ... perhaps with an error! ... you will see what firebug displays and thats the hint for the error ... play with firebug ... it will be of great help to you ... i promise ;)

        kind regards ...

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5388

          #5
          if you don't want to use firebug ... as an alternative you may use the javascript-console ... that already comes with firefox ... 'extras' -> 'Error-Console' ... there the javascript errors will be displayed too! ... its a little bit more simple ... ;)

          kind regards ...

          Comment

          • Brigitte Behrmann
            New Member
            • Jun 2007
            • 25

            #6
            Originally posted by gits
            if you don't want to use firebug ... as an alternative you may use the javascript-console ... that already comes with firefox ... 'extras' -> 'Error-Console' ... there the javascript errors will be displayed too! ... its a little bit more simple ... ;)

            kind regards ...
            Will give it a try. Thanks again.

            Comment

            Working...