Javascript Array Question 21

Introduction

Get Average

Analyze an array's value and print the average.

function get_avg(arr) {
  var sum = 0;
  //your code
  return avg;
}
get_avg([1,2,3,4]);


function get_avg(arr) {
  var sum = 0;
  for (var i = 0; i < arr.length; i++) {
    sum += arr[i];
  }
  var avg = sum / arr.length;
  return avg;
}
get_avg([1,2,3,4]);



PreviousNext

Related