Private eye


function StudentReport() {
this.grade1 = 4;
this.grade2 = 2;
this.grade3 = 1;
this.getGPA = function() {
return (this.grade1 + this.grade2 + this.grade3) / 3;

var myStudentReport = new StudentReport();

for(var x in myStudentReport) {
if(typeof myStudentReport[x] !== "function") {
console.log("Muahaha! " + myStudentReport[x]);

console.log("Your overall GPA is " + myStudentReport.getGPA());

Could anyone tell we haven't defined any parameters in
// var myStudentReport = new StudentReport();

how we are using it then??


You're defining what would be the parameters as constants within the function. You could pass in g1, g2, g3 and set this.grade1 = g1, etc, called as var myStudentReport = new StudentReport(4, 2, 1); But instead you're defining them statically in the constructor itself.


@recurvata thanks , now i got it!!


I still need help!

Wait a minute...


Something I don't understand: If we make grade1, grade1 and grade3 private variables, then how come we can still access them outside of the StudentReport constructor function? I know that when we construct the new myStudentReport object from the prototype StudentReport, then myStudentReport inherits all the properties of StudentReport. But how come we can access myStudentReport's grade1/grade2/grade3 variables for the purposes of adding/averaging them, but not for printing them?


replace this with var and modify the getGPA by deleting the this.