Get Programming with JavaScript - Listing 3.16

Listing 3.16 - A player object

var player; player = { name: "Kandra", health: 50, place: "The Dungeon of Doom", items: "a rusty key, The Sword of Destiny, a piece of cheese" }; console.log(player.name); console.log(player.name + " is in " + player.place); console.log(player.name + " has health " + player.health); console.log("Items: " + player.items);

Further Adventures

Listing 3.16 - A player object - Task 1

var player; var player2; // declare a second variable player = { name: "Kandra", health: 50, place: "The Dungeon of Doom", items: "a rusty key, The Sword of Destiny, a piece of cheese" }; // Create a second player object // Assign it to the second variable player2 = { name: "Dax", health: 30, place: "The Old Library", items: "a feather duster" }; console.log(player.name); console.log(player.name + " is in " + player.place); console.log(player.name + " has health " + player.health); console.log("Items: " + player.items);

Listing 3.16 - A player object - Task 2

var player; var player2; player = { name: "Kandra", health: 50, place: "The Dungeon of Doom", items: "a rusty key, The Sword of Destiny, a piece of cheese" }; player2 = { name: "Dax", health: 30, place: "The Old Library", items: "a feather duster" }; console.log(player.name); console.log(player.name + " is in " + player.place); console.log(player.name + " has health " + player.health); console.log("Items: " + player.items); // Log their details console.log(player2.name); console.log(player2.name + " is in " + player2.place); console.log(player2.name + " has health " + player2.health); console.log("Items: " + player2.items);