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 The Solution

Stacey Graham
Stacey Graham
7,039 Points

Why does the directory index appear when I try to run my code?

The directory index appears when I try to run my code in the browser. Why is this happening?

4 Answers

Steven Parker
Steven Parker
231,184 Points

Showing the directory listing is the default behavior when the landing page is not present.

So most likely, your landing page has been named something other than "index.html", or it is located in a sub-folder instead of the root folder.

If you still have trouble, make a snapshot of your workspace and post the link to it here so we can get a better look at the situation.


Update: So you have an "index.html" file, but it's currently located in the "css" sub-folder. Move it to the root folder so it will become the default landing page when you start the preview.

Also, the page is expecting to find the "math.js" file in the "js" sub-folder, but it is currently in the root folder. Move it into the "js" folder so the page can find it.

You can move the files by dragging them in the files pane, or you can enter these commands in the Console pane:

mv css/index.html .:point_left: note the period there after the space
mv math.js js

Stacey Graham
Stacey Graham
7,039 Points

Where is the command pane? I can't drag the some of the files.

Steven Parker
Steven Parker
231,184 Points

I meant Console pane (I fixed it above), it's usually down at the bottom. But dragging the files in my fork(copy) also seemed to work.

Also, when the files are in the right places you'll only see a blank page because there are some syntax errors in the JS:

  • on line 25 there are two missing quote marks
  • on line 31 there is an extra assignment symbol
Steven Parker
Steven Parker
231,184 Points

It looks like the dragging did re-arrange things, but not quite in the right places. Here's how they look now:

:open_file_folder:css
:open_file_folder:js
  math.js
finished.png
index.html
styles.css

And here's how they should be arranged:

:open_file_folder:css
styles.css
:open_file_folder:js
math.js
finished.png
index.html

You could drag them to the right places, or use these commands (not both):

mv css/js .
mv css/index.html .
mv css/finished.png .

And there's some new issues in "math.js":

  • on line 25 there is a missing operator ("+") after "secondNum"
  • on line 31 there is still an extra assignment symbol ("=")
  • below line 31 there are several lines mixing HTML code with the JavaScript
Stacey Graham
Stacey Graham
7,039 Points

I'm still having trouble dragging these files to the right folders. What do you have to enter in the console in addition to the mv commands? here is my workspace https://w.trhou.se/iizq3w4uhz

Stacey Graham
Stacey Graham
7,039 Points

I finally got it to run correctly! Thanks Steven for your help!