Listing 6.08 - Getting strings for a player’s health and location
JS Bin
var getPlayerHealth;
var getPlayerPlace;
getPlayerHealth = function (playerName, playerHealth) {
return playerName + " has health " + playerHealth;
};
getPlayerPlace = function (playerName, playerPlace) {
return playerName + " is in " + playerPlace;
};
console.log(getPlayerHealth("Kandra", 50));
console.log(getPlayerPlace("Kandra", "The Dungeon of Doom"));
Listing 6.08 - Getting strings for a player’s health and location - Task 1
- Create a showPlayerInfo function with three parameters: playerName, playerHealth and playerPlace.
- Call getPlayerHealth and getPlayerPlace from your new showPlayerInfo function.
var getPlayerHealth;
var getPlayerPlace;
var showPlayerInfo; // declare a variable
getPlayerHealth = function (playerName, playerHealth) {
return playerName + " has health " + playerHealth;
};
getPlayerPlace = function (playerName, playerPlace) {
return playerName + " is in " + playerPlace;
};
// define a function and
// assign it to your variable
showPlayerInfo = function (playerName, playerHealth, playerPlace) {
console.log(getPlayerHealth(playerName, playerHealth));
console.log(getPlayerPlace(playerName, playerPlace));
};
// test your new function
showPlayerInfo("Kandra", 50, "The Dungeon of Doom");