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 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.