Get Programming with JavaScript - Listing 6.14

Listing 6.14 - Displaying player information using objects

const getPlayerName = pName => pName; const getPlayerHealth = (pName, pHealth) => `${pName} has health ${pHealth}`; const getPlayerPlace = (pName, pPlace) =>`${pName} is in ${pPlace}`; const getBorder = () => "================================"; const getPlayerInfo = (playerName, playerPlace, playerHealth) => { return ` ${getPlayerName(playerName)} ${getBorder()} ${getPlayerPlace(playerName, playerPlace)} ${getPlayerHealth(playerName, playerHealth)} ${getBorder()} `; }; const player1 = { name: "Kandra", place: "The Dungeon of Doom", health: 50 }; const 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));