I have been working on Javascript in codecademy and have a doubt on one of the questions.
Question:
Write two functions:
one creates an object from arguments
the other modifies that object
My answer:
//First, the object creator
function makeGamePlayer(name,totalScore,gamesPlayed) {
//should return an object with three keys:
// name
// totalScore
// gamesPlayed
var myObject = {
"name": name,
"totalscore" : totalscore,
"gamesPlayed" : gamesPlayed
};
return myObject;
}
//Now the object modifier
function addGameToPlayer(player,score) {
//should increment gamesPlayed by one
//and add score to totalScore
//of the gamePlayer object passed in as player
var score = player[totalscore];
score =score+1;
player[totalscore] = score;
}
Not sure where my error is. Need some guidance on improving this solution.. Many Thanks...
scoretoplayer.totalscore, but you're assigningscore + 1toplayer.totalscoreinstead. Also, be wary of brackets notation, as it requires strings:player["totalscore"], notplayer[totalscore].totalScoreparameter. That is all.