Social Icons

Pages

Wednesday, November 30, 2016

Introduction to Objects I 8/33

Accessing Properties
Now that we know how to make objects with properties, let's look at how we actually use them!
Notice our example objects bob and susan. In this case both bob and susan each have two properties, name and age.
After creating our objects we have added code to access these properties. Notice that we save bob's name, "Bob Smith", into the global variable name1. We do this in line 10.

Instructions
Finish the exercise by filling in the code inlines 13 and 14 to access the name and agefor susan and save those into the given global variables.

var bob = {
  name: "Bob Smith",
  age: 30
};
var susan = {
  name: "Susan Jordan",
  age: 25
};
// here we save Bob's information
var name1 = bob.name;
var age1 = bob.age;
// finish this code by saving Susan's information
var name2 =susan.name;
var age2 =susan.age;

No comments:

Post a Comment