title: Using an array inside a constructor using Javascript
body: <p>I've been trying to find a way to correctly define an array as one of the constructor values. Let's say we have a student and we need to have an array with his grades and then using the array we need to get an average from the student's grades. Sadly, I only found some threads addressing this in other programming languages.  This is what I thought would work:</p>
  
  <pre><code>function student(name, surname, number, grades) {
  this.name = name;
  this.surname = surname;
  this.number = number;
  this.grades = [];
  this.average = function(grades) {
   var sum = 0;
   for(var i = 0; i &lt; grades.length; i++) {
    sum + = grades[i];}
    var average = sum / grades.length;
    return average;
   }
  }
  </code></pre>
  
  <p>And then</p>
  
  <pre><code>var student1 = new student("Peter","Cat",14444,[2,3,4]);
  console.log(student1);
  </code></pre>
  
  <p>Unfortunately, it shows my grades array as blank and I can't see if my average function is working properly. Which part(s) should I change so that I would actually have some values in the grades array?</p>
  
  <p>Thank you.</p>