Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
/* Get Programming with JavaScript
 * Listing 6.10
 * Displaying player information using objects
 */
var getPlayerName = function (playerName) {
    return playerName;
};
var getPlayerHealth = function (playerName, playerHealth) {
    return playerName + " has health " + playerHealth;
};
var getPlayerPlace = function (playerName, playerPlace) {
    return playerName + " is in " + playerPlace;
};
var getBorder = function () {
    return "================================";
};
var getPlayerInfo = function (playerName, playerPlace, playerHealth) {
    var playerInfo;
    playerInfo = "\n" + getPlayerName(playerName);
    playerInfo += "\n" + getBorder();
    playerInfo += "\n" + getPlayerPlace(playerName, playerPlace);
    playerInfo += "\n" + getPlayerHealth(playerName, playerHealth);
    playerInfo += "\n" + getBorder();
    playerInfo += "\n";
    return playerInfo;
};
var player1 = {
    name: "Kandra",
    place: "The Dungeon of Doom",
    health: 50
};
var player2 = {
    name: "Dax",
    place: "The Old Library",
    health: 40
};
console.log(getPlayerInfo(player1.name, player1.place, player1.health));
console.log(getPlayerInfo(player2.name, player2.place, player2.health));
/* Further Adventures
 *
 * 1) Add an items property to both players.
 *    e.g. items: "a rusty key, a piece of cheese"
 *
 * 2) Create a getPlayerItems function to return
 *    a sensible string including the items.
 *
 * 3) Update the getPlayerInfo function to
 *    include a call to getPlayerItems.
 *
 * 4) Change the two calls to getPlayerInfo
 *    so they also pass the items property
 *    as an argument.
 *
 */
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
jrlarsenpro
0viewers