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

Michael Williams
PRO
Michael Williams
Pro Student 8,057 Points

I keep getting this error, "Failed to load script.js:1 resource: the server responded with a status of 404 (Not Found)."

I get the aforementioned error in the console, but I can't figure out what's going on for the life of me. Anyone catch my mistake?

var html = " "; 

for ( var i = 1; i <= 10; i += 1 ) {
  html += "<div>" + i + "</div>"; 
}
document.write(html);
<!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>

2 Answers

Nejc Vukovic
Nejc Vukovic
Full Stack JavaScript Techdegree Student 35,752 Points

Hi Michael.

<!- your code ->
<script src = "js/script.js"></script>

<!- should be ->
<script src="js/script.js"></script>

As you see in your code you added a space after 'src' and after '=' sign.

It's a syntax error -> there are no spaces to be present and it says it can't load it because it can't find it - but it's just a syntax error.

Hope this helps.

Michael Williams
Michael Williams
Pro Student 8,057 Points

Thank you Nejc. I didn't realize that whitespace mattered in HTML.

Ali Abbas
Ali Abbas
2,096 Points

I'm honestly surprised by this because I have space in my 'src' and '=', but my code still ran. I thought space didn't matter in coding languages and if it does, then I'm surprised my one works. Weird :-/

mersadajan
mersadajan
15,520 Points

Weirdly my has no spaces but has the same error!

port-80-4q2qxiwckv.treehouse-app.com/:9 GET http://port-80-4q2qxiwckv.treehouse-app.com/js/script.js net::ERR_ABORTED 404 (Not Found)

'''<!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> '''

Nejc Vukovic
Nejc Vukovic
Full Stack JavaScript Techdegree Student 35,752 Points

Hi Mersad.

Your problem is that the script could not be found because you have a / in your path which means look at the root of your file system.

// This is your code
<script src="/js/script.js"></script>

//Should be:
<script src="js/script.js"></script>

I hope this helps.

Enjoy JS :D