Page 182 - Web_Application_v2.0_C12_Fb
P. 182
Output of the preceding program is as follows:
2.2 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.write("I love adventure stories!");
document.write("Mysteries are fun too!");
The following output will be in two lines.
document.writeln("I love adventure stories!");
document.writeln("Mysteries are fun too!");
Example 1: To create a JavaScript program
<!DOCTYPE HTML>
<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("Welcome to my website!");
document.write("I enjoy traveling and photography!");
document.write("<br><br>");
document.writeln("Greetings, visitor!");
document.writeln("Coding and gaming are my favorite hobbies!");
</SCRIPT>
</PRE>
</BODY>
</HTML>
180 Touchpad Web Applications (Ver. 2.0)-XII

