You are on page 1of 39

c  

 
                 
         c     c    
      
         
  c      <SCRIPT></SCRIPT>



<HTML>
<HEAD>
<TITLE>The Script Tag 1</TITLE>

<SCRIPT>
document.write("<P>Script tags can be placed ")
document.write("in the Head of an HTML document.</P>")
</SCRIPT>

</HEAD>

<BODY>
<H1>The Script Tag: Example 1</H1>
<P>Script tags can also be placed in the Body of an HTML
document.</P>

<SCRIPT>
document.write("<P>Script tags will be ignored by ")
document.write("browsers that do not understand them.</P>")
</SCRIPT>

</BODY>
</HTML>


i  
 i 

     
              
           !   c   
    "           
    c       <SCRIPT></SCRIPT>
   
 #        c       

 
   
    


         
      
   $         c     

             






c        %  % & % %    
    '      c       (
document.write("<P>Script tags can be placed ")
document.write("in the Head of an HTML document.</P>")

 !  
   
 !  

 
               
      
  #                    
(

<P>Script tags can be placed in the Head of an HTML document.</P>

     ) *+


          
  
   
       





    c      (

a = 2 + 3

c               

    
        %=%  
  2 + 3      5 
  
   5    a

"    ! 


   
    
       
    
a  
,  
      c          
                   
    

i 
   V

# $    c  !   *  , " 





   -               
 
 


     %

%   

     '   <SCRIPT Language="JavaScript">   


 c  #           

  
   
 


<HTML>
<HEAD>
<TITLE>The Script Tag 2</TITLE>

<SCRIPT Language="JavaScript">
document.write("<P>JavaScript is not the only scripting
language ")
document.write("planned for the internet...</P>")
</SCRIPT>
</HEAD>

<BODY>
<H1>The Script Tag: Example 2</H1>

<SCRIPT Language="JavaScript">
document.write("<P>... so it is a good idea to declare the
language ")
document.write("you are using.</P>")
</SCRIPT>

</BODY>
</HTML>

-".$

,       


    


  %   %   
 !c         

              c     
  c         
   /   
  
 

          
     
  

 
    !       
#   

   (

<!--This is a comment.-->

  
0122  
       
   

<SCRIPT> 
  
    
  &   

</SCRIPT>
c   
    
    

  33     c        
 (

<SCRIPT Language="JavaScript">
<!--

// -->
</SCRIPT>

c            <!--     // -->




<HTML>
<HEAD>
<TITLE>The Script Tag 3</TITLE>

<SCRIPT Language="JavaScript">
<!-- //Hide Script from non-script browsers
document.write("<P>Browsers that do not understand the SCRIPT
tag " )
document.write("will ignore it and treat the script statements
")
document.write("inside the SCRIPT tags as HTML</P>")
// -->
</SCRIPT>

</HEAD>

<BODY>
<H1>The Script Tag: Example 3</H1>
<P>
<SCRIPT Language="JavaScript">
<!--
document.write("To do this we also surround the script
statements ")
document.write("with HTML comments. We also must preface the
closing ")
document.write("HTML comment tag with a JavaScript comment
//")
// -->
</SCRIPT>
</P>
</BODY>
</HTML>
V

=   
   
V

"  c  4  


       & '  &2  
 

 


 ! &     
   

       
 
          '      
  
     
c         &     &
# 
 $  %           !      
  
   %              (

document.write("<P>Hello
World</P>")
 VV
¢ V V
V V  V  VV
V
V
V VV 
VV
 V V
VV
 V
V  VV V
V V


VV V V


V
V V
V

V V
V
V
V V
V  
V
 V
V
V V

VVV
V

i
VV


V
V
V
V V
Vwrite()V
 V V    Vi
VV
V
 VVV
V  V
V

V V
  V V V V V
  V V V
Vi
V
 VV
V V V
V
V V
V V 
V V
VV
 V
V
V V V
V
V 
VV

V  VV
V
V V  V

V V V
V  V
V
V
V
VV  V V
V 
V V

V
 V
V
V
 V

document.bgColor 2    


   
     
   
document.location 2   )5     
document.lastModified 2            


VVV


 VV
write()V VV
 V V
VV   V
  VV
V
V
Vwrite()VV
VV  V V
VV
V
Vi
V V
 V  V
VV
V
V

!
V¢ VV

 V V
V
V 
V
V V
 Vi
V

 VV

V

V V
V
V 

V V

VV
VV
V
V V
V
V"
V

V

VVV

 V  VV
i
V
V!
V
V VV#
#V  V V
V  V$i VV V  V
V
V
V

V%V
VV

V V
V 
 V%VV
V
V V
V
V"
V
V

r       =  


V

=


  
                    
   '    

OV V
V 
  V V
V

V 
V 
V
 VV
 V
V
&VV
OV V
V V
V

' V
V VV V
&VV
OV V  V V

 VV V
V V


VV
 ! 
         
        
/ 

#    

   !     
 .       
 
           
            
  2   
     
         
    
  
     !  
      !    

    c  ! 

 !           
   c              

   



-      !         !       
  !   !         
    
-        c    
     
 !           
    

   r 

      //
     
 // 
     
6  (

//Global Variables for the Quiz

var maxQuestions = 12 //Change this value if you want to allow more


questions.
var firstQuestion = 0 //Change this to any number from 0 to (maxQuestions -
1).

//Do Not edit code from this point on!

      r  

/* */               (

/* Global Variables for Quiz */

var maxQuestions = 12 /*Change this value if you want to allow more


questions.*/
var firstQuestion = 0 /*Change this to to any number from 0 to one less than
maxQuestions.*/

/* Do Not edit code from this point on! */

/**
* The checkAnswer(choice) method is called when the user selects an answer
* from a list of radio buttons. If the answer is correct the method returns
* true. If not it returns false. The method keeps track of the number of
* user guesses by incrementing a counter in the question object.
* The function expects one numeric parameter to be passed to it.
**/
function checkAnswer(choice){
this.guesses++
if (choice == this.answer)
return true
else
return false
}

 
  !                  
                 
      #
     
    
 2
   
 
  2      

     
  
    
  
-                       

      
  

     
V

r
#                       
    # c     
2

!    
                  c   
c                  
  
       
  
    =    
  
    (

x = 3.4

#c      


      
 (

hV 
V
V
V V 

V V
V
&Vi
V
V
V

V V 
V V
 V V 
V 
V
  V VV V
V 

V
V
V
V
VV

x
=
3.4

 V

V
V V V
V()V VV 
V
&VV
(V 


V
V

V
V V
V  
V
V V V
V
V()V VV
V 
V
VV
&VV
)V  VV
V 
VV
V V
V
 VV V

&VV
åV 
V 
V()V V 
V V
V
V 
VVV

'   !& 


x = 3.4              

*             /  % 


%    (

y = "Let's go for lunch!"

'         


7     
  

      y /         /  
         
            
c    
       
/  $  
/ 
  /            

       (

x = 3.4
y = "Let's go for lunch!"
x = y

'      !     
 
 c  
      89     
  
      
        (Let's go for lunch!'  
   


   +  !c  ! -::!  


   -!     
'  

        
     6    
   
      
c    % %

#       ! 
     
    

    
 

   c            



             
   "Let's go for
lunch!"?/           &   /  
   #               /   !  
        3.4    x    ;,  
c                   *  
          <       
 #     !                
    
    !         !  : 2  
                (

x1 = 3.14159
x2 = .5
x3 = -24e3
e             
       
  -24e3    2=9>?@8 2=9@@@

          =   


     
A  
  c   #    !  %  %    
                  x1 =
3.14159   (x1    !=   
    B 3.14159  
  

*              (     true false 


  null      
,         (

test = false
if (test) alert("test is true")

,   false  
   test   false   
   ;'              
         
 c  "     4  
     (var!function!Array!for!new!this!while! import 
  '         
"test is true"
    test   ,   false'         
       (

if (a < 10) alert("a is too small")

'     a < 10           ;'  
   ?@     
  '      
?@    ,                 
)  !                    ! 
  !   

6 !                    
           ! 
! ,         

null (

x = null

        c     ! 


! ,  
    !  c  4      

   

'           



       
   (

var x1
         ?       '    
4        '           
  
   (

var x1 = 'He said "be seeing you" as he left.'

   
    
var;      

   var                   
   

° 
r
# 

              






 /          

              
    
                      
  
              c  4  
 
          
 '   
x1!x    
     

i  r r     
var x1 = 'He said "be seeing you" as he left.'
document.write(x1)
x = "New Message"
document.write(x1)

         


 6 ?  
  
   
   
! !?     
    
  
   
)  !   
      ;
,   
 x = "New Message"       x 
       
  
 x1 
?    
      
   
%$
%  
 

  !?     
  
       
  

¢        


var x1 = 'He said "be seeing you" as he left.'
document.write(x)

          !    


    
 
  (%. (44    %         

 !                 
   


   
V





'   
 &!  /  c          


      c            
     . 
         
 / 2   2       .
   

 


                
                #     !
       


Good Morning    
 
 
     '        (
V

<HTML>
<HEAD>
<TITLE>Example of using a Date object and an if statement.</TITLE>
</HEAD>
<BODY>
<PRE>

This script provides an example of using the Date object to obtain


the hour of the day. The hour is used to write out a Good Morning
greeting if the time of day is before noon(12 hours).

<SCRIPT Language="JavaScript">

now = new Date() //create a Date object named: now

hour = now.getHours() //hours range from 0 to 23.

if (hour < 12)


document.writeln("Good Morning.")

</SCRIPT>
</PRE>
</BODY>
</HTML>
V



   22       (

now = new Date()

c     C  &    


       '  
   C  & now   
new &        
      &         
 &  
  

        
     
 
            &      
             C  &
   
      C  &   
     
    C  & now         C  
 
!   !   & C  &        
    
     

hour = now.getHours()

c         C  & getHours()  
getHours()       now     @
  
 =8??+'        ?+?8  
getHours() ?=

if (hour < 12)


document.writeln("Good Morning.")

   if          (

if (expression) statement

                     


if
     c        true false' 
   true       
   '   ! 
    $"'  !  
   hour < 12'
     (

OV V V
V
V V  V
V V%V V 

V
V V*V  V (VV
OV V V
V
V  V
Vi
V
V  V
V
V
V 
V
V V

V 
V V
V V
V  V 
V
V V
V  V
V V
V
V
V
 VV
V
V V
V  V

V V V
V  V
V V
V
V 
V V

VV

'    @ ??       ?=     
document.writeln("Good Morning.")'   ?= =8 
      Good Morning

   
' 
  
    
      $ Good
Morning 
     2  !         
 

                




 

 if           


        
       true     (

if (expression) statement

   (

if (expression)
statement
       !               
                       
             c  
          

  

                       


    true#                     
  (

if (expression)ë
statement1
statement2
statementn
}

           '                      


 #                          




"      
        true  
  
      false     (


V

<HTML>
<HEAD>
<TITLE>Example of using a Date object and an if else
statement.</TITLE>
</HEAD>
<BODY>
<PRE>

This script provides an example of using the Date object to obtain


the hour of the day. The hour is used to write out a Good Morning
greeting if the time of day is before noon(12 hours) otherwise a
generic welcome message is written into the page.

<SCRIPT Language="JavaScript">

now = new Date() //create a Date object named: now

hour = now.getHours() //hours range from 0 to 23.

if (hour < 12)


document.writeln("Good Morning.")
else
document.writeln("Welcome.")
</SCRIPT>
</PRE>
</BODY>
</HTML>
V

     if else                  


          true      
       false       
 22 
    


              (

if (expression)ë
statement1
statement2
statementx
}
else ë
statementa
statementb
statementn
}
  
   DE  
          
 
                 
      

  
       
V
ð VV

          


  
   
   
(

OV ifV 

 &VV
OV if elseV 

 &VV
OV   V
 V  V V<, <=, >, >=, ==,V V!=V
V
V V 
 &VV
OV  V 
V
Velse ifV V V
VV
OV V
 VV V VV



  
             true false
        )  !      -!-::!+! c  
          
            
 $   hour     
     c   
         
   


 < V




V 
V

hour = 2 trueV
result = hour < 3

hour = 2 falseV
result = hour < 2

hour = 2 falseV
result = hour < 1



  <= V




V 
V

hour = 2 trueV
result = hour <= 3

hour = 2 trueV
result = hour <= 2

hour = 2 falseV
result = hour <= 1



V

 > V




V 
V

hour = 2 falseV
result = hour > 3

hour = 2 falseV
result = hour > 2

hour = 2 trueV
result = hour > 1



V

  >= V




V 
V

hour = 2 falseV
result = hour >= 3

hour = 2 trueV
result = hour >= 2

hour = 2 trueV
result = hour >= 1


ð  == V




V 
V

hour = 2 falseV
result = hour == 3

hour = 2 trueV
result = hour == 2

hour = 2 falseV
result = hour == 1



-
  != V




V 
V

hour = 2 trueV
result = hour != 3

hour = 2 falseV
result = hour != 2

hour = 2 trueV
result = hour != 1





6               
  
            
 
      
 (

þ
V+
V ,
 V -
V

hV return = 4.9 == 5.0 V falseV

 V return = 4.99 == 5.0 V falseV


(V return = 4.999 == 5.0 V falseV

)V return = 4.9999 == 5.0 V falseV

åV return = 4.99999 == 5.0 V falseV

.V return = 4.999999 == 5.0 V falseV

/V return = 4.9999999 == 5.0 V falseV

0V return = 4.99999999 == 5.0 V falseV

1V return = 4.999999999 == 5.0 V falseV

h*V return = 4.9999999999 == 5.0 V falseV

hhV return = 4.99999999999 == 5.0 V falseV

h V return = 4.999999999999 == 5.0 V falseV

h(V return = 4.9999999999999 == 5.0 V falseV

h)V return = 4.99999999999999 == 5.0 V falseV

håV return = 4.999999999999999 == 5.0 V falseV

h V return = 4.9999999999999999 == 5.0 V trueV

hV return = 4.99999999999999999 == 5.0 V trueV

hV return = 4.999999999999999999 == 5.0 V trueV

hV return = 4.9999999999999999999 == 5.0 V trueV

  V return = 4.99999999999999999999 == 5.0 V trueV




'            +          
           +     
                
   
             /            
 c         
   F'...  
2    
          A       ' 
   
           
    
   
 
      
             

 2=8? 2=8?2?6    
     
       
         
       
           A'   
     ==               /   
  

V

i!
"   


now = new Date()


hour = now.getHours()

if (hour < 12)


document.writeln("Good Morning.")

     



       
' !  
 !    
         
 
 

(

i!V V

— 
VV VVV

  VV VVV


VV VV V



'       



       
  


   
  
     (
now = new Date() //create a Date object named: now

hour = now.getHours() //hours range from 0 to 23.


//0 is midnight to before 1 AM.

if (hour < 12)


document.writeln("Good Morning.")

if (hour > 17)


document.writeln("Good Evening.")

 !
  

        & 
                        

                   (

if (hour < 12)


document.writeln("Good Morning.")
else if (hour > 17)
document.writeln("Good Evening.")
else
document.writeln("Good Afternoon.")

'     else    if else      

               
    
      
(

if (hour < 12)


document.writeln("Good Morning.")
else
if (hour > 17)
document.writeln("Good Evening.")
else
document.writeln("Good Afternoon.")

                        ?=
             ?=       if else
   '       
  ?G'  ! 
 
    
   !    !   
       

                   
        
A    
     .  
              

.               (

if (hour < 12) ë


document.writeln("Good Morning.")
}
else if (hour > 17) ë
document.writeln("Good Evening.")
}
else ë
document.writeln("Good Afternoon.")
}


#              
(

if (hour > 11  hour < 18)


document.writeln("Good Afternoon.")


     HH          " 
   '   hour > 11     true   hour < 18  
    true' c                

                
  (

hour > hour < hour > 11 && hour <





V 11V 18V 18V

hour = 2
if (hour > 11  hour < 18) falseV trueV falseV
document.writeln("Good
Afternoon.")

hour = 14
if (hour > 11  hour < 18) trueV trueV trueV
document.writeln("Good
Afternoon.")

hour = 19
if (hour > 11  hour < 18) TrueV falseV falseV
document.writeln("Good
Afternoon.")

  hour > 11  hour < 18   true    true' 
    false           
     !    (

if (hour < 12)


document.writeln("Good Morning.")

if (hour > 11  hour < 18)


document.writeln("Good Afternoon.")

if (hour > 17)


document.writeln("Good Evening.")


                      
true    true      (




V !V
trueV
(true false)

(false true)V trueV

trueV
(true true)

falseV
(false false)



6 !  
    
      ?=!??!?F! ?G 
    !      
       
          
 
      
    
  
          
  (

morning = 0 //Morning begins at midnight?


noon = 12 //Afternoon begins at noon.
evening = 18 //Evening begins at 6 PM.

    (


V

<HTML>
<HEAD>
<TITLE>Examples of using a Date object and the if and
if else statements.</TITLE>
</HEAD>
<BODY>
<PRE>

This script provides examples of using the Date object


to obtain the hour of the day. The hour is used to
print different messages at different times during
the day.

<SCRIPT Language="JavaScript">

now = new Date() //create a Date object named: now

hour = now.getHours() //hours range from 0 to 23.


//0 is midnight to before 1 AM.

noon = 12 //Afternoon begins at noon.


evening = 18 //Evening begins at 6 PM.

if (hour < noon)


document.writeln("Good Morning.")
else if (hour < evening)
document.writeln("Good Afternoon.")
else
document.writeln("Good Evening.")

</SCRIPT>
</PRE>
</BODY>
</HTML>
V

$ (morning = 0            @


 
??             
  
( if (hour >
11  hour < 18)         

ð 
V    
   
     (

i!V V

-
"VV VV#V

— 
VV $VVV

  VV VVV


VV VV V

hV ,
V
V V
VV
V  
V
V
V
 V 
VV
 V " 
V
V

V
VV
 V
  V V
V V V
V V 

 V V V V


V 

 V2VV

VV
V


V
V V
VV
VV
(V i
VV  V
ViVV  VVV
V V 
V
V
Vhour = now.getHours()V


VV
V VVV
V
VV

Vhour = 2V3  
V
V
V
VV
V V
V V V
V V 
V 
V V
V V V
V 
V

V 
V  V
V
 V VV

V
V3 
V
 V V
V  V V*V VåV.V0VhhVh VhåV
h/Vh0V *V V (V¢
V

V 
 V
VV
VVV
4V" 4V V 'V 
VV


VV
VV
V
V
V V V
V V
V VV V 
VVVV



       
V
 
         if! if else!if else if else! 
switch                         
 
    


if (expression) statement
if (expression)
statement
if (expression) {
statement1
statement2
statementn
}


if (expression) statement1; else statement2
if (expression) statement1
else statement2
if (expression)
statement1
else
statement2
if (expression) {
statement1
statement2
}
else {
statement_x
statement_y
}

"""
if (expression1) {
statement1
}
else if(expression2) {
statement2
}
else if (expression3) {
statement3
}
else {
default statement
}

 
 
         c  ?=       
switch (expression) {
case 19:
statement
break
case true:
statement
break
case "hello":
statement
break
default:
statement
break
}










#
5  
            ! '    
;
V

<HTML>
<HEAD><TITLE>Examples of if, if else, and else if in
JavaScript</TITLE>
</HEAD>
<BODY>
<SCRIPT Language="JavaScript">
<!--
document.write("<H3>Simple if statements</H3>")
document.write("<P>")
var x = 2
if (x == 2) document.write("x is 2")
document.write("</P>")

document.write("<P>")
x = 3
if (x == 2) document.write("x is 2")
document.write("</P>")

document.write("<H3>Simple if else statement</H3>")


document.write("<P>")
x = 10
if (x < 10) {
document.write("x is less than 10")
}
else {
document.write("x is not less than 10")
}
document.write("</P>")

document.write("<H3>if else if else if else...


statements</H3>")
document.write("<P>")
x = 10
if (x < 10) {
document.write("x is less than 10")
}
else if (x > 10) {
document.write("x is greater than 10");
}
else {
document.write("x is equal to 10");
}

document.write("</P>");

// -->
</SCRIPT>

</BODY>
</HTML>

!       "# 


V

.
 


       
 6   

     !           
! 
     !    
         
       
              
         !   
!    
         
 !       ! 
 ,
                     
  
 


               (

while(expression) statement

# 
 c            true     
                      
         (

while(expression)ë
statement
statement
statement
}

,            !        


  '          
!  
   '    
          
      #       !   ! 
          
    while (
V

<HTML>
<HEAD>
<TITLE>Simple While Loop with Counter Variable</TITLE>
</HEAD>

<BODY>
<PRE>Output from a simple while loop with a counter variable:
<SCRIPT Language="JavaScript">
<!--

counter = 0
while (counter < 5)ë
document.writeln(counter)
counter++
}

// -->
</SCRIPT>
</PRE>
</BODY>
</HTML>
V




'   !        '     (
counter < 5  
 (

counter = 0
while (counter < 5){
document.writeln(counter)
counter++
}

  
         (

counter = 0VV

K

V

 V
VV 

V
VcounterV
V V
VV5
Vi  V 
V
VV
VV
V


VV
 V 
V

V5
V V
V  V5V

while (counter < 5)VV

i
V

 Vcounter < 5V V

V 
V5
V V
V  V 
V
V

 V

V
V
V V
VVVV
V


V
document.writeln(counter)VV

 
V
VVV
V  V 

V V


V VV
V
V
V V
V
counterV
V

counter++VV

i
V 
V
V V 


VVhV V
V V VV V5
V
V

V  V


V V


VVV
V
!VV
V 
 V¢ V  V V
V V 

V V
V
V
V 
V

 VV
V


V¢ V  
VhV V
V  VåV
VVVV
V



V V

     counter        #     

       
 

â  

            


     !
 
              
,  
      
   counter 
   
     '          !% 
 
%
       I             
     


       !      !  


   !      
 !       % %   
   

=

'         
  
   
       
   
!
  4    3   A!      
   
          (

counter = 0
while (counter < 10){
document.writeln(counter)

}
       
        
counter++      
     
 '          
      
                 
    (

while (true){
document.writeln("Some message..")
}

$        true 

 $ð! 


  
 
      !      
         
      $      
length   
 &# !   
  
  @!?!=! 
  charAt()    
 &        

      chr           
 '    
 Hello World  length ??      
@ 
?@ counter     @          
 !      @!?!=!8!9!J!K!G!F!L! ?@    
 ! counter   ?? counter < str.length 
   
 
V

<HTML>
<HEAD>
<TITLE>Examining Every Character in a String</TITLE>
</HEAD>

<BODY>
<PRE>Examining every character in a string:
<SCRIPT Language="JavaScript">
<!--

str = "Hello World"


counter = 0
while (counter < str.length){
chr = str.charAt(counter)
document.writeln(chr)
counter++
}

// -->
</SCRIPT>
</PRE>
</BODY>
</HTML>
V
chr          
2 

 -  

        #         
  
  counter        6    !
 
 
       "           
    
   

(
V

<HTML>
<HEAD>
<TITLE>Examining Every Character in a String</TITLE>
</HEAD>

<BODY>
<PRE>Examining every character in a string:
<SCRIPT Language="JavaScript">
<!--

str = "Hello World"


counter = 0
while (counter < str.length){
chr = str.charAt(counter)
document.writeln("Character in position " + counter + ": " +
chr)
counter++
}

document.writeln("The string length is: " + str.length)

// -->
</SCRIPT>
</PRE>
</BODY>
</HTML>

i
 
V

#           A       


  ' 
                 
true   #         
      
      
   
         A             
 counter     10        

counter = 0
while(counter < 10) ë
document.writeln("Counter is: " + counter)
counter++
}
       

   for       
(

for (initial statement; expression; end statement) statement



%V!%VV

i  V 
V V


V

V V
 V

&' !!
VV

i  V

 V V

VVtrueVVfalseV VtrueV
VVV V


V

V!%VV

i  V 

V V


V 
V
VVV  V

V


VV

V
V

 V V


V V

for (counter=0; counter < 10; counter++) {


document.write("Counter is: " + counter)
}

         /  


V

<HTML>
<HEAD><TITLE>Examples of using JavaScript loops</TITLE>
</HEAD>
<BODY>
<PRE>
Sample file showing a while and for loop with a
counter variable looping through values 0 through 9.

<SCRIPT Language="JavaScript">
<!--
counter = 0

document.writeln("With the while loop:")

while(counter < 10) {


document.writeln("Counter is: " + counter)
counter++
}

document.writeln("With the for loop:")

for (counter=0; counter < 10; counter++) {


document.writeln("Counter is: " + counter)
}

// -->
</SCRIPT>
</PRE>
</BODY>
</HTML>
V

         counter        
    
   !        i
                
6 !   

     
         
    

'        
        
          /         (
V

<html>
<head>
<title>i During and After a Loop</title>
</head>

<body bgcolor="#FFFFFF">
<PRE>
<SCRIPT Language="JavaScript">
<!--
document.writeln("Counting from 0 to 9 with a while loop.")

i = 0
while (i < 10){
document.writeln("Inside the loop i is: " + i)
i++
}

document.writeln("After exiting the loop i is: " + i)

document.writeln("\nCounting from 0 to 9 with a for loop.")


for (i = 0; i < 10; i++){
document.writeln("Inside the loop i is: " + i)
}

document.writeln("After exiting the loop i is: " + i)

//-->
</SCRIPT>
</PRE>
</body>
</html>
V



      (

Counting from 0 to 9 with a while loop.


Inside the loop i is: 0
Inside the loop i is: 1
Inside the loop i is: 2
Inside the loop i is: 3
Inside the loop i is: 4
Inside the loop i is: 5
Inside the loop i is: 6
Inside the loop i is: 7
Inside the loop i is: 8
Inside the loop i is: 9
After exiting the loop i is: 10

Counting from 0 to 9 with a for loop.


Inside the loop i is: 0
Inside the loop i is: 1
Inside the loop i is: 2
Inside the loop i is: 3
Inside the loop i is: 4
Inside the loop i is: 5
Inside the loop i is: 6
Inside the loop i is: 7
Inside the loop i is: 8
Inside the loop i is: 9
After exiting the loop i is: 10

c$ %  
V

=


c         parseInt()   ! !  
  
               (

result = parseInt("4.73 Hello")

'    


"4.73 Hello"parseInt()      

       
'     !   9

   resultc            parseFloat()
       
            6  (

result = parseFloat("4.73 Hello")

    9G8


 
   result'       
        
 
  
      
 $ $   % 2 2  %

.         


             
  
           .   
      
 '   parseFloat() parseInt()       
  c   .
         %  
%
% 
%6       
        (

OV V 
V V

VparseIntV V
VV


VVV
V   VV 
V V


VV
OV VVV
V
VV
V  VVV V%V  V V
V  V"4.73 Hello"VV
OV 
V VV#
 #VV
V V V

V
V
V
V V
V   V 
V V
V V


VV

c                    


            % %     
                  
      

â
%


#      c              
     
   c                  

 !    
       
      
 6                &   c  
    !       c          
   
      !    
      
     
          
           
 c     (

function functionName(parameter_1, parameter_2, .. parameter_n){


statement1
statement2
statementn
}

 function      #        
                c   
                      
 
                 
                

                  $     
       
    
   
return    
          
  2  
 

function getMax(n1, n2){


if (n1 < n2)
return n2
else
return n1
}
          
 
V

<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT Language="JavaScript">
<!--

function getMax(n1, n2)ë


if (n1 < n2)
return n2
else
return n1
}

// -->
</SCRIPT>
</HEAD>

<BODY>
<SCRIPT Language="JavaScript">
<!--

document.write("<P>")
document.write("The largest number of 5 or 6 is: " + getMax(5, 6))
document.write("</P>")

// -->
</SCRIPT>
</BODY>
</HTML>

                c   
                 
                       
                  !  
      getMax(5, 6)     (

hV 
V
VV
VåV V.V V
V

V V V
VgetMaxV   Vi

VV
V

V
V V
V
Vn1V Vn2V


&VV
 V 
V V 

V V
V   V
  V V


V V
V
V &VV
(V 
V
V V
V
V
V V

V V  V
V V
V 

Vreturn n2V
 V
V

V.VV

     2            2  return


                '   
return            K  
              
document.write("The largest number of 5 or 6 is: " + getMax(5, 6))

    

document.write("The largest number of 5 or 6 is: " + 6)

6 ! 
          


The largest number of 5 or 6 is: 6

       

c     2 2 



    
     
    c      
   
 
   
        
 ! 
     !    
  
! 2   !       !   '    ! 
       c  

    /    

        

V
V !
!!V V"V4 V() *V"V%V V"V
V  V+)V%V'%
V V'% "!
!V%V%!)*V"V
,%%-
'V!%!V !V+)V )V+ %!.V
/ V%V
V%)V%V V"V
V%!V V%!V
V
!V V%V,%%-
'V ! V() .V 0"V
!V V ! V

() !V%V+V V" . V


0"V
V%V%V %
V )V%'"%
V"% % !V %'"%+V%V

! V%V"V ! .V! *V"V

%V% V+
V
"V%V %.V