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

Needs to be in HTML Write a defining table and a function to multiply each eleme

ID: 3701181 • Letter: N

Question

Needs to be in HTML

Write a defining table and a function to multiply each element in an array by some value. The function must have this header:

If the multiply function were called like this:

The multiply function would return an array with these values: [ 51, 24, 27, 15, 60 ]

To test your function, write a separate function that is called from the onclick attribute of a button. This separate test function should create one or more arrays, call the countEvens and multiply functions, and display the values returned from countEvens and multiply.

Explanation / Answer

<html>

<body>

<p id="res"></p>

<script>

function multiply(list, multiplier) {

for (i = 0; i < list.length; i++) {

list[i] = list[i] * multiplier;

}

return list;

}

function countEvens() {

var list = [ 17, 8, 9, 5, 20 ];

var products = multiply(list, 3);

document.getElementById("res").innerHTML = products;

}

</script>

<button>Multiply</button>

</body>

</html>

  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote