Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

content not displaying on web page

<!DOCTYPE html>
<html>
<head>
<link href="quotes.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
<!--hide the script from old browsers

function getQuote() {
//create the arrays

quotes= new Array(4);
sources = new Array(4);

//initialize the Array with quotes

quotes[0] = "I hope that after I die, people will say of me-That guy sure owed me a lot of money.";
sources[0] = "Jack Handy";
quotes[1] = "Don't ever get your speedometer confused with your clock, like I did once, because the faster you go the later you think you are.";
sources[1] = "Jack Handy";
quotes[2] = "If a kid asks where rain comes from, I think a cute thing to tell him is God is crying.And if he asks why God is crying, + 
another cute thing to tell him is-Probably because of something you did.;
sources[2] = "Jack Handy";
quotes[3] = "When you're riding in a time machine way far into the future, don't stick your elbow out the window, or it'll turn into a fossil.";
sources[3] = "Jack Handy";
quotes[4] = "The first thing was, I learned to forgive myself. Then, I told myself, "Go ahead and do whatever you want, it's+ okay by me";
sources[4] = "Jack Handy";

//Get random index into the arrays

i = Math.floor(Math.random() * quotes.length);

//write out quote as html

document.write("<dl style='background-color: lightblue'>\n");
document.write("<dt>" + "\"<em>" + quotes[i] + "</em>\"\n");
document.write("<dd>" + "." + sources[i] + "\n");
document.write("<dl>\n");
}
//stop hiding the script-->

</script>

<title>Deep Thoughts</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body> 
<div id= intro>
<h1>Deep Thoughts</h1>
<p>You can live by</p>
<p>reload this page</p>
</div>
<script type="text/javascript">

<!--Hide the script from old browsers

getQuote();

//Stop hiding the script-->

</script>

</body>
</html>

4 Answers

Paul Johnson
Paul Johnson
18,924 Points

You are putting single line comments(//) before you code, so it is all getting commented out, try putting each statement on a different line and indenting the code, it will make reading it, and fixing it, easier.

Example

 //Create the array
quotes = new Array(4);
sources = new Array(4);

Instead of

//create the arrays quotes= new Array(4); sources = new Array(4);

You are also missing the opening and closing script tags, and a few html tags.

Hope this helps

Thanks Paul, how do you display the code in a markdown box like that?

Thanks Paul, how do you display the code in a markdown box like that?

Paul Johnson
Paul Johnson
18,924 Points

Three backticks (```) at the start and end of the code, there is a Markdown Cheatsheet link underneath the post's.

~~~ this worked on the US keyboard. very good thanks.

It also looks like you are missing the closing quotation mark for the quotes[2] item.