Click to See Complete Forum and Search --> : questions regarding randome quotes


belotte
05-30-2003, 01:13 AM
I have a new question. I am using this script to post random quotes on my web page. Right now it’ll only accommodate a specific number. It seems to me that to change the number of quotes I would have to change either the 1 or the 5, or both. The problem is I can’t seem to figure out which one and how. Any ideas? The cod is as follows.

Thank you so much,

Richard Belotte

<!-- Begin
var a = Math.random() + ""
var rand1 = a.charAt(5)
quotes = new Array

quotes[1] = "The object of art is to give life a shape. -Jean Anouilh"

quotes[2] = "Sometimes I've believed as many as six impossible things before breakfast. -Lewis Carroll."

quotes[3] = "Hitch your wagon to a star. -Ralph Waldo Emerson"

quotes[4] = "We should not let our fears hold us back from pursuing our hopes. -John F. Kennedy"

quotes[5] = "Not failure, but low aim is a crime. -James Russell Lowell"

quotes[6] = "Art is not a mirror to reflect the world, but a hammer with which to shape it. -Vladimir Mayakovski"

quotes[7] = "Without art, the crudeness of reality would make the world unbearable. -George Bernard Shaw"

quotes[8] = "Art is the only way to run away without leaving home. -Twyla Tharp"

quotes[9] = "Art imitates nature in this: not to dare is to dwindle. -John Updike"

quotes[0] = "Success follows doing what you want to do. There is no other way to be successful. -Malcolm Forbs"

var quote = quotes[rand1]
document.write(quote);
// End -->

Gollum
05-30-2003, 02:06 AM
how about

var rand1 = Math.round(Math.random() * nQuotes) % nQuotes;


rand1 should be an integer from 0 to nQuotes - 1

havik
05-30-2003, 02:12 AM
The problem was that the variable a received a value like:
a= 0.2414536664
and the 5th character in this bunch was selected as your "random" number. In this case, only single digits were selected.

Try this instead, where 12 is the number of quotes you have plus 1. So if you have 28 quotes, use 29.

var a = Math.random() * 12;
randl = Math.floor(a);


Havik

Nevermore
05-30-2003, 03:02 AM
I think this way would be better, because you can have any number of quotes without having to change it:


<script type="text/javascript">
<!-- Begin

quotes = new Array

quotes[1] = "The object of art is to give life a shape. -Jean Anouilh"

quotes[2] = "Sometimes I've believed as many as six impossible things before breakfast. -Lewis Carroll."

quotes[3] = "Hitch your wagon to a star. -Ralph Waldo Emerson"

quotes[4] = "We should not let our fears hold us back from pursuing our hopes. -John F. Kennedy"

quotes[5] = "Not failure, but low aim is a crime. -James Russell Lowell"

quotes[6] = "Art is not a mirror to reflect the world, but a hammer with which to shape it. -Vladimir Mayakovski"

quotes[7] = "Without art, the crudeness of reality would make the world unbearable. -George Bernard Shaw"

quotes[8] = "Art is the only way to run away without leaving home. -Twyla Tharp"

quotes[9] = "Art imitates nature in this: not to dare is to dwindle. -John Updike"

quotes[0] = "Success follows doing what you want to do. There is no other way to be successful. -Malcolm Forbs"

var a = Math.random() *(quotes.length+1);
a = Math.floor(a);
var quote = quotes[a]
document.write(quote);




// -->
</script>

Nevermore
05-30-2003, 03:04 AM
oops, that should have been:


<script type="text/javascript">
<!-- Begin

quotes = new Array

quotes[1] = "The object of art is to give life a shape. -Jean Anouilh"

quotes[2] = "Sometimes I've believed as many as six impossible things before breakfast. -Lewis Carroll."

quotes[3] = "Hitch your wagon to a star. -Ralph Waldo Emerson"

quotes[4] = "We should not let our fears hold us back from pursuing our hopes. -John F. Kennedy"

quotes[5] = "Not failure, but low aim is a crime. -James Russell Lowell"

quotes[6] = "Art is not a mirror to reflect the world, but a hammer with which to shape it. -Vladimir Mayakovski"

quotes[7] = "Without art, the crudeness of reality would make the world unbearable. -George Bernard Shaw"

quotes[8] = "Art is the only way to run away without leaving home. -Twyla Tharp"

quotes[9] = "Art imitates nature in this: not to dare is to dwindle. -John Updike"

quotes[0] = "Success follows doing what you want to do. There is no other way to be successful. -Malcolm Forbs"

var a = Math.random() *(quotes.length);
a = Math.floor(a);
var quote = quotes[a]
document.write(quote);




// -->
</script>

havik
05-30-2003, 05:01 PM
Ah yes, that eluded me. That way would be easier. :D

Havik