JavaScript program to print the Average of given n Numbers
Following program shows you how to print average of given n numbers.
let arrayOfNums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
function calculateAverage(array) {
var total = 0;
var count = 0;
array.forEach(function(item, index) {
total += item;
count++;
});
return total / count;
}
console.log(calculateAverage(arrayOfNums));
Output:
8
Try it Online here https://onecompiler.com/javascript/3x5qdhzjy