Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a JaveScript function showArraySum (ref, ar) that is passed (1) a string r

ID: 3925119 • Letter: W

Question

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

Explanation / Answer

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;

}