Task 1 — Your first JavaScript page
JavaScript is included in an HTML document using the <script> tag. The standard command for writing output to a page is document.write() — document is a built-in object representing the HTML document, and write() is a method of that object.
- Run the code and look at the output.
- Declare another variable and display it with
document.write(). - Notice that
//starts a JavaScript comment.
Code
<h1>My First JavaScript Page</h1>
// Output statement
document.write("Welcome to my website.<br>");
// Declare variables and display them
var title = "Faizal's Site";
document.write("This is " + title + ".");