Write a JaveScript function showArraySum ref ar that is pass
Write a JaveScript function showArraySum (ref, ar) that is passed (1) a string ref that is the value of the id attribute of an element of the HTML document and (2) an array ar of numbers. It appends the sum of the array elements to the content of the clement with ref as the value of its id attribute. For example, suppose that the HTML document has an empty div element with id \"result\": And suppose that showArraySum () is called as follows. showArraySum (\"result\", [1, 2, 3]); Then the content of the div element we become as follows (rendered simply as 6). 6
Solution
function showArraySum(ref,ar)
{
var div=document.getElementById(ref);
var sum=0
var count
for(count=0;count<ar.length;count++)
{
sum=sum+ar[count];
}
div.innerHtml=sum;
}
