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 named countEvens that

ID: 3701156 • Letter: N

Question

Needs to be in HTML

Write a defining table and a function named countEvens that counts and returns the number of even integers in an array. The function must have this header:

Make sure that you write your functions to handle an array of any size.

Hint: 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

<!DOCTYPE html>

<html><head></head>

<body>

<h3>::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::</h3>

<p><button type="button">Show Result</button></p><p id="result"></p>

<script>

function clickme() {

var list = [1, 7, 4, 3, 6, 9, 2, 10, 11];

var multiplier = 3;

var string = "Array list: "+list+ "
" + "Even numbers of the array list: " + countEvens(list) + "
" + "Array list after multiplied by 5: " + multiply(list, multiplier);

document.getElementById("result").innerHTML = string;

}

function countEvens(list) {

var even_numbers = [];

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

if ((list[inc] % 2) === 0) {

even_numbers.push(list[inc]);//push in to array even_numbers foreach

}

}

return even_numbers;//at last resturn even_numbers

}

function multiply(list, multiplier) {

return list.map(function (list) {

return list * multiplier;

});

}

</script>

</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