30. Private Eye - Question


#1


https://www.codecademy.com/en/courses/objects-ii/5/4?curriculum_id=506324b3a7dffd00020bf661


Code works. I have a question about the codecademy code, though. I don't quite understand the 'if' argument - I see it's doing the for in loop to go through the object. But I'm not sure what it 'not' equal to a "function" means? Can anyone help?

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


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


#2

It checks if property on myStudentReport object is not identical to function or is not of function type. This let's you determine what properties are not functions.


#3

Thanks, elv1nas. That helps!


#4

can you be more detail pls


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.