Styling fonts in javascript arrays?

hi
i am new to javascript but trying to get a handle on it. i have a javascript that prints a random array message:

<SCRIPT>
quote0= "Time is on our side. -John Mervish";
quote1= "A bird in the hand is worth two in the bush. -Frank Templeton";
quote2= "But I dont have the wings and I wonder why. -Miss Prince";
var ran_unrounded=Math.random()*2;
var ran_number=Math.round(ran_unrounded);
document.write(eval("quote"+ran_number));
</SCRIPT>

anyway, the code is styled by a wrapper <div id=“dottedsidebar”>, but i want to have more than one style to each line (expample quote0: have ‘Time’ in bold, have ‘-John Mervish’ in #FF0000 and 2px smaller while rest of quote is #000000). how can i achieve this?

you can put different portions of each quote in a <span> and then style each <span> as you like.

btw - the variables you have there are not an array or elements of an array.

thanks for the post. so you are saying that i can assign <span> tags to javascript fonts and style them? i will give that a try! and you posted that it is not an array? sorry am learning. question: is styling through javascript the same as css? eg -

quote0= "<span class="treatment_a">Time</span> is on our side. -John Mervish";

So now you are creating an array called “quote” that you never use and variables called “quote0”, “quote1” etc that have values.

The JavaScript to do what you expect that code to do is:

var quote=["Time is on our side. -John Mervish",
"A bird in the hand is worth two in the bush. -Frank Templeton",
"But I dont have the wings and I wonder why. -Miss Prince"];
document.write(quote[Math.floor(Math.random()*quote.length)];

You might also consider setting up an id in the page where the quote is to go and then replace the document.write with document.getElementById(xxx).innerHTML so that the script can be kept out of the HTML and can be run after tha page has loaded.

you’re not accessing an array element with quote0.

There are a few ways you can create an array. The “traditional” ways are

 
var myArray = new Array();
myArray[0] = 'value 1';
myArray[1] = 'value 2;
myArray[2] = 'value 3';

or simply

 
var myArray = new Array('val 1','val 2','val 3');

and to use an array element in your script the syntax is typically

 
alert(myArray[COLOR=red][[/COLOR][COLOR=red]2[/COLOR][COLOR=red]][/COLOR]);

thanks for the help all. i really appreciate it.

thanks for the help all. i really appreciate it. Felgall, i attempted to incorporate the ID tagging in my html document, but for whatever reason it wont work. i have a

<div id="ranQuote"></div>

and then the script

var quote=["Time is on our side. -John Mervish",
"A bird in the hand is worth two in the bush. -Frank Templeton",
"But I dont have the wings and I wonder why. -Miss Prince"];
document.getElementById('ranQuote').innerHTML (quote[Math.floor(Math.random()*quote.length)]);

but nothing appears. surely i am missing somthing, i have looked around online trying to sort out this issue but i cannot get it to display. what am i missing here?

Are you attempting to run the script before the ranQuote even exists?

Move the script to the end of the body, just before the </body> tag, or use some page onload event so that the script runs after the body content comes in to existence.