30. Private Eye


#1


So I've modified the grades to make them private and the code passes the lesson, but it doesn't print anything to the console?


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

Your code amounts to producing output, so the reason for not printing is somewhere other than in the code that you posted

$ xsel -b | node  # feed clipboard content into nodejs
Your overall GPA is 2.3333333333333335

#3

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