0

I have a very basic html file that uses a script tag to import a javascript file, but the javascript file is not run when I load the html locally in a browser. How am I formatting the script tag incorrectly?

Folder Structure

-folder
  --test.html
  --script.js

test.html

<html lang="en">
<head>
  <meta charset="utf-8">
  <title>TEST</title>
</head>

<body>
  <p>TEST</p>
  <script type='text/javascript' src="script.js" />
</body>
</html>

script.js

console.log('HELLO WORLD')

(function () {
  setTimeout(() => alert('HELLO WORLD'), 3000)
})();
Jon_B
  • 591
  • 2
  • 10
  • 16
  • Does this answer your question? [How to run a function when the page is loaded?](https://stackoverflow.com/questions/4842590/how-to-run-a-function-when-the-page-is-loaded) – R Greenstreet Jan 27 '21 at 22:10
  • You can't use self-closing tags for ` – Daniel Beck Jan 27 '21 at 22:33

2 Answers2

2

You should close your script tag in a separate tag :

<script type="text/javascript" src="script.js"></script>
terrymorse
  • 5,564
  • 1
  • 14
  • 19
0

Your script tag is incorrect it should be : <script type='text/javascript' src="script.js"></script>