Page 291 - Web Applications (803) Class 11
P. 291
4.8 THE WRITE() AND WRITELN() METHODS
Both methods are used to display output on the web page. The write() method writes straight to an open (HTML)
document stream (A stream an object that allows to read/write data). The writeln() method also writes directly
to an open HTML document stream, with the addition of writing a newline character after each statement. For
example:
The following output will be in a single line.
document.writeln("I love reading Harry Potter books");
document.writeln("I also love reading murder mysteries");
The following output will be in two lines.
document.writeln("I love reading Harry Potter books");
document.writeln("I also love reading murder mysteries");
Let us create a JavaScript program:
<HTML>
<HEAD>
<TITLE> Using write() and writeln() Methods </TITLE>
</HEAD>
<BODY text="blue">
<H2> The write() and writeln() Methods </H2>
<PRE>
<SCRIPT TYPE="text/javascript">
document.write("Hello!");
document.write("I love eating pasta and pizza!");
document.write("<br> <br>");
document.writeln("Hello!");
document.writeln("I love eating pasta and pizza!");
</SCRIPT>
</PRE>
</BODY>
</HTML>
Introduction to Dynamic Websites Using JavaScript 289

