Page 373 - Webapplication11_C11_Flipbook
P. 373

for (i = 2; i <= num; i+=2) {
                   document.write(i+"<BR><BR>"); }

                   </SCRIPT>
                   </P>
                   </BODY>
                   </HTML>
                 On running the above program, we get the following output:

















                 When you click on the “OK” button, with the message “This page says”. Then a new windows appears as shown below:






















                 Example:

                   <HTML>
                   <BODY text="green">
                   <h2> program to accept a number and display its factorial </H2>
                   <P style="color:blue;">
                   <script>
                   var num=parseInt(prompt("Enter a number"));
                   var fact=1

                   for (i = num; i > 0; i--) {
                     fact=fact*i;  }
                   document.write("The factorial of "+num+" is "+fact);
                   </SCRIPT>
                   </P>
                   </BODY>
                   </HTML>

                                                                                                  JavaScript Part 1  371
   368   369   370   371   372   373   374   375   376   377   378