Make Your Own Random Quote Generator

Ever wanted to create your own random quotes area? Here's a quick and simple Javascript setup for that, where you create an array of quotes, calculate the index, then tell your browser to display them.

Javascript Code:
  1. <script type="text/javascript">
  2.  
  3. //store your quotations in arrays
  4. quotes = [];
  5. authors = [];
  6.  
  7. quotes[0] = "Art is like masturbation. It is selfish and introverted and done for you and you alone. Design is like sex. There is someone else involved, their needs are just as important as your own, and if everything goes right, both parties are happy in the end";
  8. authors[0] = "Colin Wright";
  9.  
  10. quotes[1] = "I love the comment, “You must love designing for a living.” At that point I usually start to laugh or break into uncontrollable tears";
  11. authors[1] = "Andrew Lewis";
  12.  
  13. quotes[2] = "Good design is all about making other designers feel like idiots because that idea wasn’t theirs";
  14. authors[2] = "Frank Chimero";
  15.  
  16. quotes[3] = "Marketing without design is lifeless, and design without marketing is mute";
  17. authors[3] = "Von R. Glitschka";
  18.  
  19. //calculate a random index
  20. index = Math.floor(Math.random() * quotes.length);
  21.  
  22. //tell your browser to show your quotations
  23. document.write("<strong><dl>");
  24. document.write("<dt>" + "" + quotes[index] + "<br />");
  25. document.write("<dd>" + "-- " + authors[index] + "<br />");
  26. document.write("</dl></strong>");
  27. </script>
  28.  

And now you get a result like this, that refreshes itself on each page load:

Add comment


Security code
Refresh

Search

Visit fbetting.co.uk Betfair Review