CodeOrc.com - Learn by example
X
Make an RPG
Vue Implementations

Javascript objects

Objects are variables that hold other variables.

This is an object with 0 variables

var player = {};

Here is an object with 3 variables:

var player = { "hit_points": 5, "max_hp": 10, "class_type": "Fighter" };

Now let's print out the player's hit_points

print( player.hit_points );
DO IT
Try printing out the max_hp or the class_type.

Set hit points to 7.

player.hit_points = 7;

To set hit points to maximum, we do:

player.hit_points = player.max_hp;
DO IT
Try changing max_hp before the above statement and notice the difference.

In the next lesson, we will learn about Examples of how to use Spread Attributes

Get the Latest Tutorial Updates
<< >>
X