Viewing ./functionsMax.html Filesize: 0.64Kb
//This script finds the largest number given an arbitrary number of elements

<html>
<head>
<script type="text/javascript">
function max(/* ... */)
{
    
    var m = Number.NEGATIVE_INFINITY;
    // Loop through all the arguments,  looking for, and
    // remembering, the biggest
    for(var i = 0; i < arguments.length; i++)
        if (arguments[i] > m) m = arguments[i];
    // Return the biggest
    alert("m is "+m);
    return m;

}
var largest = max(1, 10, 100, 2, 3, 1000, 4, 5, 10000, 6);
alert("largest is" +largest);
</script> 
</head>

<body>

 <input type="button" value="Max" onclick="max(1, 10, 100, 2, 3, 1000, 4, 5, 10000, 6);">



</body>
</html>