Ricky158
02-20-2003, 02:47 AM
yeah, i searched this forum for the answer, but i didnt find it, btw... ;)
i want to have a list of facts (i have about 25 of them) randomly display one at a time per page view. that's pretty self-explanitory enough.
any questions? i'll gladly answer :)
glenngv
02-20-2003, 03:15 AM
<html>
<body>
<script language="javascript">
var arrFacts = new Array("fact1","fact2","fact3");
var index = Math.floor(Math.random()*(arrFacts.length-1));
document.write(arrFacts[index]);
document.close()
</script>
</body>
</html>
Ricky158
02-20-2003, 04:32 AM
thanks. :tips hat:
for some facts, i need to use quotes ("), how can i use these without making it think that i'm ending the fact?
Takes care of the quotation marks...
<html>
<body>
<script language="javascript">
var arrFacts = new Array("bob said, 'hi'.","'hello',said bob","bob's just \"weird\"");
var index = Math.floor(Math.random()*(arrFacts.length-1));
document.write(arrFacts[index]);
document.close()
</script>
</body>
</html>
I think those work. First two quotes I just used the other kind of quote. The third quote, I used escape characters. I also used a comma there to add affect :cool:
Good Luck :thumbsup:
Ricky158
02-20-2003, 05:36 AM
okay, thanks. and do i need the forward slash when using other characters like dashes and the percent sign?
glenngv
02-20-2003, 08:36 AM
no, only with " or ', depending on your string delimeter used.
if you use ' as your string delimeter and you have ' within the string, you need to put \' inside the string.
if you use " as your string delimeter and you have " within the string, you need to put \" inside the string.
"bob's just \"weird\""
is the same as:
'bob\'s just "weird"'