我一直在 codecademy 中研究 Javascript,并且对其中一个问题有疑问。
问题:
写两个函数:
one creates an object from arguments
the other modifies that object
我的答案:
//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;
}
不知道我的错误在哪里。需要一些有关改进此解决方案的指导。非常感谢...