baby_20
12-09-2005, 03:22 AM
Write the code for a function name maxValue() with two parameters, named theArray and numValues. The Javascript function should use a loop and a conditional statement to FIND THE MAXIMUM VALUE IN THE ARRAY and then return the value.
The user of the page should populate the array by an inputbox (window.prompt) using a for loop.
It is asked as well that we use the parseInt() function to convert the input data to integer
<html><head>
<title>Vicky</title>
<script type="text/javascript">
function maxValue(theArray, numValues){
var maxValue = 0
for(i=0; i<theArray.length; i++)
if(theArray[i] > maxValue)
maxValue = theArray[i];
</script></head>
<body>
<form id="finalForm" name="finalForm">
<input name="button1" value="button1" type="button"><br>
<br>
<input name="text1" value="text1" size="20" type="text">
</form>
</body></html>
The user of the page should populate the array by an inputbox (window.prompt) using a for loop.
It is asked as well that we use the parseInt() function to convert the input data to integer
<html><head>
<title>Vicky</title>
<script type="text/javascript">
function maxValue(theArray, numValues){
var maxValue = 0
for(i=0; i<theArray.length; i++)
if(theArray[i] > maxValue)
maxValue = theArray[i];
</script></head>
<body>
<form id="finalForm" name="finalForm">
<input name="button1" value="button1" type="button"><br>
<br>
<input name="text1" value="text1" size="20" type="text">
</form>
</body></html>