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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Chelsea Byerly](https://secure.gravatar.com/avatar/18a08f089802184bd56cc0cbd638bc15?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Chelsea Byerly
175 Pointsusing js/ before the file name vs. not when linking a file via script tag
I've noticed that in some tutorials, we are instructed to indicate js/ before the file name when linking another file in a script tag. For example, <script src="js/strings.js"></script>, but in other tutorials, that seems to be left out. For example, <script src="strings.js></script>. The video above uses the former method, yet during a coding challenge, I was marked incorrect for using the js/ before the file name. Some clarification on this would be appreciated. Thanks!
1 Answer
![Michael Hulet](https://uploads.teamtreehouse.com/production/profile-photos/672712/micro_me.jpg)
Michael Hulet
47,912 PointsThe src
attribute (like many other HTML attributes, such as href
) takes a file locator, which can be as specific as a full URL or as flexible as a file path relative to the current document, like it sounds like you’re usually doing.
If your JavaScript file lives in the same folder as your HTML file on the server, all you need to reference it is just the name of the JavaScript file. However, if your HTML file is in the same folder as another folder which in turn holds your JavaScript file, then it would be appropriate to prefix the name of the file with the name of the folder that contains it followed by a forward slash (/
)
For example, let’s say I have an HTML file called index.html
and a JavaScript file in the same folder on the server called script.js
. I might include that JavaScript file in that HTML by adding a tag like this to index.html
:
<script src=“script.js”></script>
However, if script.js
was contained in a folder called js
, and that folder is in the same folder as index.html
, I might include it like this:
<script src=“js/script.js”></script>