logo CodeStepByStep logo

evenAverage

Language/Type: JavaScript basics arrays
Author: Melissa Hovik (on 2017/08/14)

Write a JavaScript function which takes an array of integers as a parameter and returns the average of all even integers in the array.

For example, a call of evenAverage([1, 2, 3, 4, 8, 7, 6, 5]) should return 5 (since only the four values 2, 4, 6, and 8 are considered in the calculation of the average result) and evenAverage([5, 4, 3]) should return 4 since 4 is the only even integer in the array.

If the array passed is empty or does not contain any even integers, return 0. You may assume the array passed is non-null.

Function: Write a JavaScript function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.