0

I've already pretty well at html and css. Now i considering learn JS and when i link my html file to the JS file, it's not working.

Here's my html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Test Java Script</title>
    <script scr="script.js"></script>
  </head>
  <body>
    <!--<h1>Hello</h1>
    -->
    <script>
      alert("if this page blank, external js file not executed!")
    </script>
  </body>
</html>

and here's my javascript

document.write("works!")

It's pretty simple, just want to know if it works or not, please help me. Thank you.

2
  • is script.js in the same folder as your .html file? Commented Aug 21, 2020 at 3:38
  • 1
    there is a typo here <script scr="script.js"></script> it should be <script src="script.js"></script> Commented Aug 21, 2020 at 3:42

2 Answers 2

1

The correct word is src (source), modify this line:

scr="script.js"

src="script.js"

Sign up to request clarification or add additional context in comments.

Comments

0
<script scr="script.js"></script>

is what you have...

<script src="script.js"></script>

should work...

document.write("Works!");
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Test Java Script</title>
    <script src="script.js"></script>
  </head>
  <body>
    <!--<h1>Hello</h1>
    -->
    <script>
      alert("if this page blank, external js file not executed!")
    </script>
  </body>
</html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.