Get Programming with JavaScript - Listing 2.07

Listing 2.07 - Declaring and assigning in one step

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

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

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

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

Video Tutorials

Single step declaration and assignment