Chapter 5. Your First JavaScript Script

IN THIS CHAPTER

  • Creating a simple application consisting of an HTML page, a JavaScript script, and a CSS style sheet

In this chapter, you write a simple script, the results of which you can see in your JavaScript-compatible browser.

Two common ways of teaching spoken human languages are a) grammar lessons leading to eventual conversation and b) immersion in conversation leading to eventual grammar lessons.

We like b). It's more fun (play enhances learning), you get to see results right away, and it more closely resembles the way we each learned our own native tongue. The grammar's always there to refer to, but let's kick things off to a good start by plunging in and making a little magic happen on the screen.

Don't worry about memorizing every command and detail of syntax discussed in this chapter. Instead, relax and watch how the HTML markup and JavaScript statements become what you see in the browser. The details will soak in more quickly if you're enjoying yourself.

We'll explain each line of code as we go along, although all the methods we use in this first tutorial will be explained in much greater detail later in the book. For now, just enter the scripts as presented and see that they do what they're supposed to do.

What Your First Script Will Do

Our first tutorial script will insert the current date and time into a web page. (This is a further evolution of the "Hello, World" script we showed you in Chapter 3, "Selecting and Using Your Tools.") ...

Get JavaScript® Bible, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.