JavaScript lesson 1

1 a. Write:

Source:
     <SCRIPT TYPE="text/javascript" LANGUAGE="javascript">
     <!--
     document.write("Jan Nylund");
     //-->
     </SCRIPT>
   
1 b. Write line:

Source:
     <SCRIPT TYPE="text/javascript" LANGUAGE="javascript">
     <!--
     document.writeln("Jan Nylund");
     //-->
     </SCRIPT>
   
2 a. If I put one write and one write line together:


Source:
<SCRIPT TYPE="text/javascript" LANGUAGE="javascript">
      <!--
      document.write("Jan Nylund");
      document.writeln("Jan Nylund");
      //-->
 </SCRIPT>   
 And preformatted:
     
Source:
<PRE>
<SCRIPT TYPE="text/javascript" LANGUAGE="javascript">
<!--
document.write("Jan Nylund");
document.writeln("Jan Nylund");
//-->
</SCRIPT>
</PRE> 
2 b. One write and two write line:


Source:
   <SCRIPT TYPE="text/javascript" LANGUAGE="javascript">
   <!--
   document.write("Jan Nylund");
   document.writeln("Jan Nylund");
   document.writeln("Jan Nylund");
   //-->
   </SCRIPT>
And preformatted:

Source:
<PRE>
<SCRIPT TYPE="text/javascript" LANGUAGE="javascript">
<!--
document.write("Jan Nylund");
document.writeln("Jan Nylund");
document.writeln("Jan Nylund");
//-->
</SCRIPT>
</PRE> 
2 c. First one write line then a write and last a write line, preformatted.

Source:
<pre>
<script type="text/javascript" language="javascript">
<!--
document.writeln("Jan Nylund");
document.write("Jan Nylund");
document.writeln("Jan Nylund");
//-->
</script>
</pre>
  
2 d. In the case that I use "write" every new Jan Nylund starts where the last Jan Nylund stops in this way:

Source:
<script type="text/javascript" language="javascript">
        <!--
        document.write("Jan Nylund");
        document.write("Jan Nylund");
        document.write("Jan Nylund");
        document.write("Jan Nylund");
        //-->
</script>  
  

It do not change when I use preformatted text:

Source:
<pre>
<script type="text/javascript" language="javascript">
  <!--
  document.write("Jan Nylund");
  document.write("Jan Nylund");
  document.write("Jan Nylund");
  document.write("Jan Nylund");
  //-->
</script>
</pre>
It is because "write", writes the text without starting a new line for every new write.

2 e. When I use "write line" (writeln) the script starts on a new line for every following "write line" and it is visible when I use preformatted text:

Source:
<pre>
<script type="text/javascript" language="javascript">
      <!--
      document.writeln("Jan Nylund");
      document.writeln("Jan Nylund");
      document.writeln("Jan Nylund");
      document.writeln("Jan Nylund");
      //-->
</script>
</pre>
If the text not is preformatted there will only be a space between Jan Nylund and the next Jan Nylund:

Source:
<script type="text/javascript" language="javascript">
        <!--
        document.writeln("Jan Nylund");
        document.writeln("Jan Nylund");
        document.writeln("Jan Nylund");
        document.writeln("Jan Nylund");
        //-->
</script>

In html everything is going on the same line if no <P> or <BR> breaks the line or the line reaches the end of the window. When the script writes a new line without including a <BR> or a <P>, then no new line is visible on the screen. In a preformatted text everything is displayed on the screen like it is written:
        Jan
        Nylund
and not preformatted text: Jan Nylund


The source code looks like this:

<PRE>
         Jan
         Nylund
</PRE>
<P>
and not preformatted text:
         Jan
         Nylund
</P>


Summary: "Write line" (writeln) adds a "newline" character to the end. Write (write) does not.