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 trialAngela Riggs
2,539 PointsConsole.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
Unsubscribed User
30 PointsI 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.
Stephen Van Delinder
21,457 PointsSteve'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.
Brandon Barrette
20,485 PointsBrandon Barrette
20,485 PointsMoved this to an answer instead of a comment because, well, it's a great answer! Thanks!
Angela Riggs
2,539 PointsAngela Riggs
2,539 PointsThank you so much, Steve! I really appreciate it :)