Quotes help make search much faster. Example: "Practice Makes Perfect"

Monday, November 5, 2012

Codecademy: Sample Solution to "Using Objects" under the jQuery Track



//First, the object creator
function makeGamePlayer(name,totalScore,gamesPlayed) {
    //should return an object with three keys:
    // name
    // totalScore
    // gamesPlayed
    gamePlayerObject = {
    "name" : name,
    "totalScore" : totalScore,
    "gamesPlayed" : gamesPlayed
};
    return gamePlayerObject;
}

//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
    player.gamesPlayed++;
    player.totalScore = player.totalScore + score;
}

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts