var studentMarks = {
mathScore : 0,
englishScore : 0,
totalScore : null,
computeMarks : function (mathScore, englishScore) {
this.mathScore = mathScore;
this.englishScore = englishScore;
this.totalScore = this.mathScore + this.englishScore;
console.log(this.totalScore);
}
}
function setStudentScore(score1,score2,callback){
callback(score1,score2);
}
setStudentScore(40,50,studentMarks.computeMarks);
print(studentMarks.totalScore); //prints 'undefined'
The print statement should print 90 instead it prints undefined
. What changes should I do to the computeMarks method ?