write the program in javascript C httpsvisakaiuri.edu/access/content/attachment/
ID: 3782967 • Letter: W
Question
write the program in javascript
C httpsvisakaiuri.edu/access/content/attachment/e3dbb580-16f5-490faff0-88196032aB7c/Assignments/147rb020-747b-425a-a808-37b7198dic1b4/hw0 skeleton js.txt Program To Find the naxinum integer in an array of positive integers r array 2,12,4,18, 6.8 var array [8]; var array4 20,18,16,1 12,10,8,6 2,4,6,8 18. var array declare function findMax Nhich takes an array as its only parameter and returns the na integer in that array. Algorithm to the first element in t Set local tMax hirite a for oop fron e to the length of the array h element test to see if the list element at the index of the loop counter is greater than currentMax if it is, then set currentMex to the value of that array element After the loop end he function turn currentMax Set fill to black so text thows up on the screen. Call findMax five h of the a Print the ult of function 1 t python-360 exe a hw0 skeleton is a hw0 skeleton (1) is a Show allExplanation / Answer
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<p id="max">
</p>
<script>
var array1 = [2, 12, 4, 10, 6, 8];
var array2 = [1, 2, 15, 5, 7, 9, 11, 13];
var array3 = [8];
var array4 = [20, 18, 16, 14, 12, 10, 8, 6];
var array5 = [2, 4, 6, 8, 10, 12, 14];
var result = [];
var j = 0;
//store the maximum value in result
result[j++] = findMax(array1);
result[j++] = findMax(array2);
result[j++] = findMax(array3);
result[j++] = findMax(array4);
result[j++] = findMax(array5);
var p = '';
//append the result to p
for (var i = 0; i < result.length; i++)
p += result[i] + '<br>';
//display the results in para
document.getElementById('max').innerHTML = p;
//max value in the array
function findMax(array)
{
var maximum = array[0];
for (var i = 0; i < array.length; i++) {
if (array[i] > maximum) {
maximum = array[i];
}
}
return maximum;
}
</script>
</body>
</html>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.