Tuesday, 20 August 2013

From within a javascript var, how do you change the font color for individual lines?

From within a javascript var, how do you change the font color for
individual lines?

I'm sure this is an easy question. I have some javascript that randomizes
quotes, but I want the quote and the author of the quote to be different
colors. I can of course use CSS to change the appearance of all the text,
but I am not having much luck separating the quote and the author and I am
not very proficient with javascript.
<script language="JavaScript">
var Quotation=new Array()
Quotation[0] = "Only two things are infinite, the universe and human
stupidity, and I'm not sure about the former.<br>Albert Einstein";
Quotation[1] = "Science is a way of thinking much more than it is a body
of knowledge. <br>Carl Sagan";
Quotation[2] = "Few tragedies can be more extensive than the stunting of
life, few injustices deeper than the denial of an opportunity to strive or
even to hope, by a limit imposed from without, but falsely identified as
lying within.<br>Stephen Jay Gould";
Quotation[3] = "I don't want to talk to you no more, you empty-headed
animal food trough wiper! I fart in your general direction! Your mother
was a hamster and your father smelt of elderberries!<br>Taunting
Frenchman";
var Q = Quotation.length;
var whichQuotation=Math.round(Math.random()*(Q-1));
function showQuotation(){document.write(Quotation[whichQuotation]);}
showQuotation();
</script>

No comments:

Post a Comment