Private Eye


#1

I am stuck at 30/30, Private Eye, I legit don't know what to do, and what makes sense doesn't work. I print everything. I don't know what to do to stop it.

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

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());


I legit, give up. I just want to finish my course


#2

Hi you begin that Lesson with that code

function StudentReport() {
    var grade1 = 4;
    var grade2 = 2;
    var grade3 = 1;
    this.getGPA = function() {
        return (grade1 + grade2 + 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());

then they aske you to..

Modify the StudentReport class so that no grades will be printed to the console in the for-in loop.
instead of create that

var grade1 = this.grade1
var grade2= this.grade2
var grade3 = this.grade3

you should directly change it here

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

so where ou have

this.grade1 = 4;

you shoudl change it to

var grade1 = 4;

and where you have this.grade1 change it to just grade ........do it to all the grades inside that object
Hope that could help you


#3

I just get "Your GPA is NaN, it should return 2.3333333333333333"


#4

Can you post your new code?


#5

OH!! I fixed it thanks! I missing a small part!


#6

return (this.grade1 + this.grade2 + this.grade3) / 3;

becomes

return (grade1 + grade2 + grade3) / 3;


#7

My working exercise:

function StudentReport() {
    var grade1 = 4;
    var grade2 = 2;
    var grade3 = 1;
    this.getGPA = function() {
        return (grade1 + grade2 + 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());

#8

My working exercise.

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

var myStudentReport = new StudentReport();

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

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


#9

I have a small question, is there another method??
What if the grades could not be logged because the argument in the for/in would not be true.
I changed it, the grades don't show but the GPA does.
I changed this.getGPA into var getGPA to make it private and I get: "TypeError: StudentReport.getGPA is not a function"
how can I resolve that?
Thanks


#10

My solution:

function StudentReport() {
    var grade1 = 4;
    var grade2 = 2;
    var grade3 = 1;
    this.getGPA = function() {
        return (grade1 + grade2 + 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());