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 Basics (Retired) Introducing JavaScript The Console Challenge Answer

Console.log Messages

In the video, Dave put the console.log messages in the writes.js file. I had put them in the index.html file - I put the Start Program function after the opening body tag, and the End Program function just before the closing body tag. Here's the markdown:

<body>
  <script> console.log("Start program");</script>
  <div class="container">
  <h1>Can you get the JavaScript to work?</h1>
  <script src="scripts.js"></script>
  </div>
  <script> console.log("End program");</script>
</body>

My way worked, but is the writes.js placement the "best practice" way to do it?

2 Answers

I would say any time you have an opportunity to keep code or a stylesheet in an external script that you include in your HTML page - the better. It allows for proper separation and cleaner code. To that degree, I would say absolutely it is best practice. It won't always be the case, but in most cases it will be.

Brandon Barrette
Brandon Barrette
20,485 Points

Moved this to an answer instead of a comment because, well, it's a great answer! Thanks!

Thank you so much, Steve! I really appreciate it :)

Steve's right.

In this example, you can really get away with either, but as you get into more sophisticated code that you need to debug and refactor, you are going to want it as organized as possible.