The Daily Average

EasyAcc. 94.2%
+20 XP 8

Statistical Balance

The average (mean) is the sum of all elements divided by the total number of elements.

The Assignment

Your function receives an array values.

  1. Calculate the sum of all elements in values.
  2. Divide the sum by the length of the array.
  3. Print the result.
  4. If the array is empty, print 0.

01EXAMPLE 1

Inputvalues = [10, 20, 30]
Output20

Explanation: 60 / 3 = 20.

Constraints

  • Handle empty arrays to avoid Division by Zero.
  • Use values.length.
ArraysLoopsMath
JavaScript
Loading...
2 Hidden

Input Arguments

values[10,20,30]

Expected Output

20

Click RUN to test your solution