Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    London
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 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
    New Coder
    Join Date
    Jun 2002
    Location
    London & Oxford
    Posts
    97
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    London
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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'

  • #4
    New Coder
    Join Date
    Jun 2002
    Location
    London & Oxford
    Posts
    97
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

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