Get Programming with JavaScript - Listing 6.07
Listing 6.07 - Getting a string for a player’s name
JS Bin
var getPlayerName;
getPlayerName = function (playerName) {
return playerName;
};
console.log(getPlayerName("Kandra"));
Further Adventures
Listing 6.07 - Getting a string for a player’s name - Task 1
- Update the getPlayerName function so it adds a prefix and suffix made up of the = character. The length of the prefix and suffix should be 4.
var getPlayerName;
getPlayerName = function (playerName) {
// include a prefix and suffix
return "==== " + playerName + " ====";
};
console.log(getPlayerName("Kandra"));
Listing 6.07 - Getting a string for a player’s name - Task 2
- Update the getPlayerName function so it includes a border on the left when displaying the name.
var getPlayerName;
getPlayerName = function (playerName) {
// include a border
return "\n|\n| " + playerName + "\n|\n";
};
console.log(getPlayerName("Kandra"));