JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops For Loops

Anna Astle
Anna Astle
11,640 Points

My javascript wont run

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Circles</title> <link rel="stylesheet" href="css/styles.css"> </head> <body id="color"> <script src= "js/script.js"></script> </body> </html>

var html = ' ';

for ( var i= 1; i <= 10; i += 1) { html += '<div>' + i + '</div>'; } document.write ( html );

1 Answer

Steven Parker
Steven Parker
173,537 Points

Is that two separate files pasted above? The HTML is expecting the JavaScript to be in "script.js" inside the "js" folder, is that where it is?

To facilitate a more accurate analysis of the issue, make a snapshot of your workspace and post the link to it here.

Anna Astle
Anna Astle
11,640 Points

https://w.trhou.se/kew8948h02

I'm working on this section of treehouse: For Loops with Dave McFarland

Thanks for the link to the snapshot video. That is SO easy and helpful. As you can now see for yourself. The Javascript is in fact inside the folder js with the name script.js .

Steven Parker
Steven Parker
173,537 Points

In the snapshot, the "script.js" file is in the root (top-level) folder where "index.html" is. The "js" folder is there, but empty.

Just move the "script.js" file into the "js" folder. Either drag it using the left pane, or type "mv script.js js" in the command pane.

And would the person who downvoted this answer please leave a comment and let me know how I can improve? Thanks!

Anna Astle
Anna Astle
11,640 Points

Thanks so much! I wouldn't have caught that otherwise.