var playerName = "Kandra";
var locationName = "The Dungeon of Doom";
console.log(playerName + " is in " + locationName);
Further Adventures
Listing 2.07 - Declaring and assigning in one steps - Task 1
Declare a health variable and assign it a value in one step.
var playerName = "Kandra";
var locationName = "The Dungeon of Doom";
// declare a health variable and assign it a value
var health = 50;
console.log(playerName + " is in " + locationName);
Listing 2.07 - Declaring and assigning in one steps - Tasks 2 and 3
Declare a message variable.
Assign message a value created by joining variables and text to say something like "Kandra has health 50 and is in The Dungeon of Doom"
var playerName = "Kandra";
var locationName = "The Dungeon of Doom";
var health = 50;
// declare a message variable
var message;
// assign it a value by joining text
message = playerName + " has health " + health + " and is in " + locationName;
console.log(playerName + " is in " + locationName);
Listing 2.07 - Declaring and assigning in one steps - Task 4
Replace the current console.log statement with a new one to display the message variable.
var playerName = "Kandra";
var locationName = "The Dungeon of Doom";
var health = 50;
var message;
message = playerName + " has health " + health + " and is in " + locationName;
console.log(message); // display the message