Listing 6.09 - Getting a string for a player’s information
JS Bin
var getPlayerName;
var getPlayerHealth;
var getPlayerPlace;
var getPlayerInfo;
var getBorder;
getPlayerName = function (playerName) {
return playerName;
};
getPlayerHealth = function (playerName, playerHealth) {
return playerName + " has health " + playerHealth;
};
getPlayerPlace = function (playerName, playerPlace) {
return playerName + " is in " + playerPlace;
};
getBorder = function () {
return "********************";
};
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;
};
console.log(getPlayerInfo("Kandra", "The Dungeon of Doom", 50));
Listing 6.09 - Getting a string for a player’s information - Task 1
- Add a second call to getPlayerInfo with different player information. Log the returned string to the console.
var getPlayerName;
var getPlayerHealth;
var getPlayerPlace;
var getPlayerInfo;
var getBorder;
getPlayerName = function (playerName) {
return playerName;
};
getPlayerHealth = function (playerName, playerHealth) {
return playerName + " has health " + playerHealth;
};
getPlayerPlace = function (playerName, playerPlace) {
return playerName + " is in " + playerPlace;
};
getBorder = function () {
return "********************";
};
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;
};
console.log(getPlayerInfo("Kandra", "The Dungeon of Doom", 50));
// add a second call to getPlayerInfo
console.log(getPlayerInfo("Jahver", "The Crypt", 200));