JS newbie here and having an issue with passing parameters. I'm writing a function inside of an object and can't figure out why JS won't pass in my parameter in the function. see example below
var students = ["Joseph", "Susan", "William", "Elizabeth"]
var scores = [ [80, 70, 70, 100],
[85, 80, 90, 90],
[75, 70, 80, 75],
[100, 90, 95, 85] ]
var gradebook = {
"Joseph": {
testScores: scores[0]
},
"Susan": {
testScores: scores[1]
},
"William": {
testScores: scores[2]
},
"Elizabeth": {
testScores: scores[3]
},
addScore: function(student, score){
console.log(student) //=> output as expected
console.log(score) //=> output as expected
console.log(gradebook.Joseph.testScores) //=> this works as expected and shows Joseph's scores
console.log(gradebook.student.testScores) //=> gives TypeError: Cannot read property 'testScores' of undefined
}
};
gradebook.addScore("Joseph", 30);
I put the console log statements to debug and figure out whats going on. I have no idea why this works when I hardcode in the students name, but doesn't work when I pass in the student's name as a parameter from running the function outside of the gradebook object. Any help would be appreciated!