### Why Javascript?

Now that we've learned HTML and CSS, we're able to build beautiful websites. But there's one problem: they're static. There's no interaction with the users.

In a website built only with HTML and CSS, users can just scroll up and down and click on links. With Javascript we'll add a layer of interactivity that will make our websites much richer in terms of usability.

Users will be able to open and close menus, expand and collapse sections, navigate through photo sliders, use filters on product pages and much more. With Javascript, our website will be dynamic!

### Where to write Javascript code

Javascript code can be written inside script tags. Those look just like normal HTML elements and they can placed in the head or in the body section. For most cases the best place to include the script tags will be at the end of the body element.

        <!DOCTYPE HTML>

        <html>

            <head>
                <script>

                    // Javascript code can be written here

                </script>
            </head>

            <body>

                <!-- page content  -->

                <script>

                    // Javascript code can be written here

                </script>

            </body>
        </html>

However, the best place to write Javascript code is in separate .js files. In this case the script tag will serve as a link to that file.

        <body>

            <!-- html da página  -->

            <script src='js/scripts.js'></script>

        </body>

#### Writing the first Javascript statements

Using the scripts.js file we've just created, let's write a few statements.

        alert('Sending a message via alert');

        console.log('Sending a message via the console');

Now refresh the page and see what happens. The message passed through the alert function is shown on a popup and the message sent through the console.log function can be seen on the browser's inspector.

The things we send to the console are not for the users, this is actually an extremelly useful tool to identify mistakes in our code and uderstand what our Javascript code is doing.

### Contents