Page 374 - Webapplication11_C11_Flipbook
P. 374

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:














                                               Lab Assignment ‘n Activity                      #Interdisciplinary




                 Write JavaScript code for the following:
                 1.  Display all odd numbers from 39 till 11.
                 2.  Accept 5 numbers from the user and find their average.
                 3.  Accept two numbers from the user. Calculate first number raised to the power of second number.
                 4.  To get the first n Fibonacci numbers.
                     (  Note: the Fibonacci sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, . . each subsequent
                     number is the sum of the previous two numbers.)                                 [CBSE Handbook]



              The for….in Loop

              The for...in  statement iterates across an object’s properties. For each property, the code block inside the loop  is
              executed once. Syntax of the for loop is as follows:

                  for (i in object) {
                    block of code to be executed
                 }
              Example:
              <HTML>

                 <BODY>
                    for..in loop statement
                 </BR>
                    <script type = "text/javascript">

                          var days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday'];
                          for(const i in days){

                372     Touchpad Web Applications-XI
   369   370   371   372   373   374   375   376   377   378   379