I want to have my javascript print a random quote out of an array. I managed to do this, but don’t know how to control where it writes. I wish to write it within a div. Help?
Code:
quotes = [];
quotes[0] = "I have a new philosophy. I'm only going to dread one day at a time.";
quotes[1] = "Reality is the leading cause of stress for those in touch with it.";
quotes[2] = "Few things are harder to put up with than the annoyance of a good example.";
quotes[3] = "The pure and simple truth is rarely pure and never simple.";
quotes[4] = "There's no business like show business, but there are several businesses like accounting.";
quotes[5] = "Man invented language to satisfy his deep need to complain.";
//calculate a random index
index = Math.floor(Math.random() * quotes.length);
//display the quotation
document.write("<p>" + quotes[index] + "</p>");
Give the div an id say
dividthen usedocument.getElementById()to get the div then innerHTML to set its content;