Get Programming with JavaScript - Listing 5.13

Listing 5.13 - Displaying a player's information

var showPlayerInfo; var showPlayerName; var showPlayerHealth; var showPlayerPlace; showPlayerName = function (playerName) { console.log(playerName); }; showPlayerHealth = function (playerName, playerHealth) { console.log(playerName + " has health " + playerHealth); }; showPlayerPlace = function (playerName, playerPlace) { console.log(playerName + " is in " + playerPlace); }; showPlayerInfo = function (playerName, playerPlace, playerHealth) { console.log(""); showPlayerName(playerName); console.log("----------------------------"); showPlayerPlace(playerName, playerPlace); showPlayerHealth(playerName, playerHealth); console.log("----------------------------"); console.log(""); }; showPlayerInfo("Kandra", "The Dungeon of Doom", 50); showPlayerInfo("Dax", "The Old Library", 40);

Further Adventures

Listing 5.13 - Displaying a player's information - Task 1

var showPlayerInfo; var showPlayerName; var showPlayerHealth; var showPlayerPlace; var showLine; // Declare a variable showPlayerName = function (playerName) { console.log(playerName); }; showPlayerHealth = function (playerName, playerHealth) { console.log(playerName + " has health " + playerHealth); }; showPlayerPlace = function (playerName, playerPlace) { console.log(playerName + " is in " + playerPlace); }; // Define the function and assign it showLine = function () { console.log("----------------------------"); }; showPlayerInfo = function (playerName, playerPlace, playerHealth) { console.log(""); showPlayerName(playerName); console.log("----------------------------"); showPlayerPlace(playerName, playerPlace); showPlayerHealth(playerName, playerHealth); console.log("----------------------------"); console.log(""); }; showPlayerInfo("Kandra", "The Dungeon of Doom", 50); showPlayerInfo("Dax", "The Old Library", 40);

Listing 5.13 - Displaying a player's information - Task 2

var showPlayerInfo; var showPlayerName; var showPlayerHealth; var showPlayerPlace; var showLine; showPlayerName = function (playerName) { console.log(playerName); }; showPlayerHealth = function (playerName, playerHealth) { console.log(playerName + " has health " + playerHealth); }; showPlayerPlace = function (playerName, playerPlace) { console.log(playerName + " is in " + playerPlace); }; showLine = function () { console.log("----------------------------"); }; showPlayerInfo = function (playerName, playerPlace, playerHealth) { console.log(""); showPlayerName(playerName); showLine(); showPlayerPlace(playerName, playerPlace); showPlayerHealth(playerName, playerHealth); showLine(); console.log(""); }; showPlayerInfo("Kandra", "The Dungeon of Doom", 50); showPlayerInfo("Dax", "The Old Library", 40);

Listing 5.13 - Displaying a player's information - Task 3

var showPlayerInfo; var showPlayerName; var showPlayerHealth; var showPlayerPlace; var showLine; var showBlankLine; // Declare a variable showPlayerName = function (playerName) { console.log(playerName); }; showPlayerHealth = function (playerName, playerHealth) { console.log(playerName + " has health " + playerHealth); }; showPlayerPlace = function (playerName, playerPlace) { console.log(playerName + " is in " + playerPlace); }; showLine = function () { console.log("----------------------------"); }; // Define a function and assign it showBlankLine = function () { console.log(""); }; showPlayerInfo = function (playerName, playerPlace, playerHealth) { showBlankLine(); showPlayerName(playerName); showLine(); showPlayerPlace(playerName, playerPlace); showPlayerHealth(playerName, playerHealth); showLine(); showBlankLine(); }; showPlayerInfo("Kandra", "The Dungeon of Doom", 50); showPlayerInfo("Dax", "The Old Library", 40);