Practice: Using JavaScript and the DOM to Output Data to a Webpage
The following JavaScript program shows how to combine all of the elements described in the last 3 sections.
<html> <head> <title>First JavaScript Program </title> </head> <body> <script> /* This is an example of JavaScript */ console.log("The program is running") // Write to the console document.write("<h1>First JavaScript Program</h1>") //Print head document.write("This is my first web page with JavaScript."); document.write("<br/>This is on a new line"); alert("Here is an alert box"); </script> </body> </html>
Program 24 First JavaScript Program
The result of running this html is the following web page.
Figure 3 – Final Web Page