0

just start learn web dev ..

i created two files - html file - js file

the js file i wrote code:

function func1()
{
    alert("alert message");

    //document.writeln("document write line");

    //console.log("this is log message");

 }

The html file code:

<html>
<head>
    <script type="text/javascript" src="basicFile.js"/>
</head>

<body>
    <script>
        func1();
    </script>
</body>

Why the alert does not popup ? also the doc.writeln does not work.

When i write the js func1 directly on the html - its work fine

Yanshof
  • 9,659
  • 21
  • 95
  • 195

1 Answers1

1

Because you need to close script tag differently. Do

<script type="text/javascript" src="test.js"></script>

instead of

<script type="text/javascript" src="test.js" />
Matus Dubrava
  • 13,637
  • 2
  • 38
  • 54