Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
948 B
4
Indexable
Never
var student1  = { name : "kelly",  score : 90 };
var student2  = { name : "Apple",  score : 80 };
var student3  = { name : "Orange", score : 40 };
var student4  = { name : "Lemon",  score : 70 };
var student5  = { name : "Catty",  score : 60 };
var student6  = { name : "Danny",  score : 50 };
var student7  = { name : "Sherry", score : 80 };
var student8  = { name : "Betty",  score : 70 };
var student9  = { name : "DEDE",   score : 50 };
var student10 = { name : "Arlen",  score : 60 };

function average(student_array) {
  var total = 0;
  var num_student = student_array.length;
  for (var i = 0; i < num_student; i++)
  {
    total = total + student_array[i].score;
  }
  return total / num_student;
}

var student_array = [ student1, student2 , student3 , student4 , student5 , student6 , student7 , student8 , student9 , student10]

var average_value = average(student_array);

console.log(average(student_array))