A first script

For JavaScript to appear in a Web page you need to do much the same as you do with CSS.  You use a new element inside the head element in to hold it.  Open your HTML template _template.html and save it as jsalert.html.  If you did not do the HTML and CSS tutorials you just need an empty Web page (one which has the basic elements such as html, head, title, link and body).  In the template there is also an h1 element ready for the main heading.

Make the heading (h1) say A simple script.  Just under the h1 add a new script element by pasting this in:

<script type="text/javascript">
    alert('Hello new scripter');            
</script>

Save and view.  Watch out for a warning from your browser that it has blocked some content.  JavaScript is only a risk if the browser is badly written but some were.  Enable the blocked content and you should see another message - this time the one you asked for as explained below.

The alert function tells the browser to pop up a message to the user.  You can identify functions because they always have brackets after the function name.  Sometimes those brackets are empty but this time they hold the text to display in the message box.  Functions do stuff.  If yours didn't do anything you have done something wrong.

When loading this new page the browser looks through the HTML as usual.  When it sees the script element it knows that there is some JavaScript (the type attribute tells it this) and it does what the JavaScript tells it to do.  Scripts are instructions to the browser to do something.  HTML is instructions to put something in a Web page.  CSS is instructions to change appearance.  JavaScript is instructions to do something (in this case to show an alert message).

Put this HTML paragraph after the script element:

<p>This should only appear after the script has been run.</p>

Save and view but when the message appears note that the paragraph is not yet there.  OK the message and as soon as it clears the browser will move on to the next bit of HTML.