Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 109 - 2625 PortGPt V2.1
P. 109

    SOME MORE PROGRAMS

                      Program 7: To display the following pattern using for loop.
                      1
                      22
                      333
                      4444
                      55555

                     <!DOCTYPE HTML>
                     <HTML>
                     <HEAD>

                         <TITLE> Pattern </TITLE>
                     </HEAD>
                     <BODY>
                     <SCRIPT>
                       var i, j;
                       for(i=1; i <= 5; i++)
                       {
                         for(j=1; j<=i; j++)

                          {
                            document.write(i);
                          }
                          document.write("<br />");
                       }
                     </SCRIPT>
                     </BODY>
                     </HTML>
                     The output of Program 7 is:

                      Program 8: To add first five natural numbers.

                     <!DOCTYPE HTML>
                     <HTML>

                                                                                                   Loops in JavaScript  107

| 104 105 106 107 108 109 110 111 112 113 114 |