Page 210 - Web Applications (803) Class 12
P. 210

Output of the preceding program is as follows:















              Practice Question  3:

                  <html>
                  <body>
                  <h2>JavaScript Functions</h2>
                  <p>Function to display the average of all numbers of an array</p>
                  <script>
                  function Display_avg(arr1) {
                    var sum=0;
                    var leng=arr1.length;
                    for(i=1;i<leng;i++)
                      sum=sum+arr1[i];
                    return(sum/leng)
                    }
                    const arr1=[18,26,45,34,78];
                  var ans=Display_avg(arr1);
                  document.write("The average is " +ans);
                  </script> </body> </html>
              Output of the preceding program is as follows:















                Write a code in JavaScript to initialise a string. The program should:

                 *  Display length of the string
                 *  Print the string in upper case
                 *  Print the first two characters of the string

                 *  Print the string in reverse order                                       [CBSE SAMPLE PAPER 2020]
                Write code in JavaScript to send a string to a function as argument. The function should display the first
                 occurrence of the word “the” in the string.




                208   Touchpad Web Applications-XII
   205   206   207   208   209   210   211   212   213   214   215