Page 212 - Web_Application_v2.0_C12_Fb
P. 212
Example 22: To display the smallest and greatest values of an array of numbers
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>To display the Smallest and greatest values </TITLE>
</HEAD>
<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];
}
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>
Output:
210 Touchpad Web Applications (Ver. 2.0)-XII

