View Full Version : Random quotes script

07-05-2002, 11:41 AM
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("<DT>" + "\"" + quotes[index] + "\"\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?"";



07-05-2002, 11:57 AM
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?

07-05-2002, 12:02 PM
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?


07-05-2002, 12:24 PM
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?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum