Web Analytics Made Easy -
StatCounter Random quotes script - CodingForum

Announcement

Collapse
No announcement yet.

Random quotes script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Random quotes script

    Hey all,

    I have a .js file that contains quotes but can't get it to work...and is basically as follows

    quotes = new Array();
    quotes[0] = "quote one";
    quotes[1] = "quote two.";

    index = Math.floor(Math.random() * quotes.length);

    document.write("<DL>\n");
    document.write("<DT>" + "\"" + quotes[index] + "\"\n");
    document.write("</Dl>\n");

    My link in the body text is

    <script language="javascript" src="http://www.murphyz.co.uk/js/quote.js"></script>

    is there anything that should go in the <head> section?

    Also what would happen if I wanted the quote to have speech and needed quotation marks? i.e
    quotes[0] = "she said "does this work okay?"";

    Thanks

    Mxx
    "Imagination is more important than knowledge" A. Einstein's 'Twin Paradox'

  • #2
    Hi Murphyz

    You don't need to put anything in the <head> if you want to use this as an external script file, it can go in the <body>. Just remember that you don't need to use the

    <!--

    //-->

    comments in the external file that you would with an inline script.

    If you want to add quotation marks within your quotes, just preceed them by a backslash to 'escape' them. E.g.

    quotes[1] = "He said \"hello\" to all the children"

    Good luck

    Where abouts in London are you?
    As easy as 3.1415926535897932384626433832795028841

    Comment


    • #3
      So, theoretically, the only reason it doesn't currently work is due to the " marks not having a \ before them?

      I live N21, work SW4 - nightmare commuting! You?

      Mxx
      "Imagination is more important than knowledge" A. Einstein's 'Twin Paradox'

      Comment


      • #4
        Yeah, stick the backslashes in and it should work. If it doesn't then the error message should point you at the line number and position of the offending bit.

        I work in South Ruislip but live near SW19 so I've got nightmare commute too but doesn't everyone?
        As easy as 3.1415926535897932384626433832795028841

        Comment

        Working...
        X