Write this in java script programming Your assignment is to
Write this in java script programming
Your assignment is to write a program that has a function to find the largest element in an array. You may write your program in the Khan Academy Javascript.
You must use the following in your program:
Global variables (the five arrays/lists)
Arrays, or in Python Lists, (the five arrays/lists)
A function that you define (findMax)
A function parameter (the array/list you pass to the function)
A local variable (currentMax in the function findMax)
A loop (the main part of the function findMax)
A conditional (the test to see if there is a new currentMax value)
A function return value (currentMax is returned at the end of findMax)
Output (putting the maximum values on the screen.
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 allSolution
<!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>

