How HTML and JavaScript Work Together in a Browser

You’ve just created your first web page. Now let’s make the page a little more interactive. Create another file in your kittenbook directory called kittenbook.js. This will be a JavaScript file, and it will make your web page more interesting.

Open kittenbook.js with your text editor and fill it with the code in Listing 1.3.

Listing 1.3 Hello, Friend!

alert('Hello, [your name]!');

Replace [your name] with your real name. For me, this would be alert('Hello, Steven!').

Now open your web page again (or reload it) and see what happens. It’s a trick! The page should look exactly the same as it did before. The HTML doesn’t know that the JavaScript exists, and that’s because we didn’t tell the HTML ...

Get Learning to Program now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.