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

document.write("The greatest number is "+result);
                    </script>

                    </body> </html>
                 Output of the preceding program is as follows:
















                 Practice Question  2:

                    <html>
                    <body>

                    <h2>JavaScript Functions</h2>
                    <p>Function to display the smallest, greatest values of an array of numbers</p>
                    <script>
                    function Display_max(arr1) {
                      var max_val=arr1[0];

                      for(i=1;i<arr1.length;i++){
                        if (max_val < arr1[i])
                          max_val = arr1[i];
                      }
                 Output of the preceding program is as follows:

                      document.write("<br>"+"The maximum value of the array is "+max_val);
                    }
                    function Display_min(arr1) {
                      var min_val=arr1[0];
                      for(i=1;i<arr1.length;i++){
                        if (min_val > arr1[i])
                          min_val = arr1[i];
                      }
                      document.write("<br>"+"The minimum value of the array is "+min_val);
                    }
                    const arr1=[14,66,45,24,53];
                    Display_max(arr1);
                    Display_min(arr1);
                    </script> </body> </html>






                                                                                          Web Scripting—JavaScript   207
   204   205   206   207   208   209   210   211   212   213   214