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 JavaScript Loops, Arrays and Objects Tracking Data Using Objects Using `for in` to Loop Through an Object's Properties

Mirali Mirzayev
Mirali Mirzayev
1,980 Points

HTML Set up

Hello Everyone could you please help me out with my HTML syntax in Atom:
<!DOCTYPE html> <html> <body> <script src = "helloworld.js"></script> <p></p> </body> </html>

JavaScript is not printing out into the screen because of something wrong here.

Thank you in advance.

Justinas Vebra
Justinas Vebra
1,053 Points

This is the correct HTML to begin with:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" href="css/main.css">
  <title>Title</title>
 </head>
<body>
   <script src="helloworld.js"></script> 
</body>
</html>

I assume you wanted to print out some text with the help of JavaScript, so just add this part to the helloworld.js file:

document.write("Hello, World!");

Again, the JavaScript part is shown because of the assumption. Let me know if this is helpful or more information is needed.

1 Answer

Could be a simple problem of not referring correctly to where your javascript file is located. I always put my javascript files in a JS folder. Assuming you're working in the root folder of your project the pathing would be <script src = "js/helloworld.js"> or if you're in another folder and want to move up a directory first you could put down <script src = "../js/helloworld.js">.

If it's a problem with actual code please put down the code form your helloworld.js