JavaScript files inclusion

You can write JavaScript code in a separate file, which will be included then in the HTML file. Let's see how it's done.

First, let's create a file with our script. This file needs the extension .js. For example, let's name this file script.js. Let's put some code in it:

script.jsalert('text');

Now, let's include our script in the HTML file. To do this, in the tag script in the attribute src you need to put the path to the script file:

index.html<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <script src="script.js"></script>
  </head>
  <body>
    
  </body>
</html>
Задание 1

Make a script file. Include it in your HTML file. Check out its work.