Currently struggling with creating a code that my friend and I were assigned. The task is to calculate and return the average of all values in an array called customerBalance. This array represents the amount customers owe my fictional business, with each item in the array representing a customer's balance. The goal is to use a for loop to process the array, calculate the average by dividing the sum by the length of the customerBalance array, and then return this average.
This is what I have attempted so far:
function average() {
customerBalance
for(i=0,i++)
sum(customerBalance)
total=sum/5
return average;
I am aware that this code is completely wrong. I am unsure how to properly work with arrays and would appreciate any guidance on how to approach this problem. Your help is greatly appreciated!
Thank you and have a wonderful day