Java Reference
In-Depth Information
Click OK, and again the parsing continues, with the third paragraph, Paragraph 3, being displayed.
The web page is complete, as shown in Figure 1-5.
Figure 1-5
The fi rst part of the page is the same as in our earlier example. The background color for the page is set
to white in the defi nition of the <body> tag, and then a paragraph is written to the page.
<html>
<body bgcolor=”WHITE”>
<p>Paragraph 1</p>
The fi rst new section is contained in the fi rst script block.
<script type=”text/javascript”>
// Script block 1
alert(“First Script Block”);
</script>
This script block contains two lines, both of which are new to you. The fi rst line —
// Script block 1
is just a comment , solely for your benefi t. The browser recognizes anything on a line after a double for-
ward slash (//) to be a comment and does not do anything with it. It is useful for you as a programmer
because you can add explanations to your code that make it easier to remember what you were doing
when you come back to your code later.
The alert() function in the second line of code is also new to you. Before learning what it does, you
need to know what a function is.
Functions are defi ned more fully in Chapter 3, but for now you need only think of them as pieces of
JavaScript code that you can use to do certain tasks. If you have a background in math, you may already
have some idea of what a function is: A function takes some information, processes it, and gives you a
result. A function makes life easier for you as a programmer because you don't have to think about how
the function does the task — you can just concentrate on when you want the task done.
Search WWH ::




Custom Search