Contact List

I Organization With Objects
i. What you’ll be building 1/8
Save and Submit
ii. Creating your contact object 2/8

var friends = {
 
};

iii. Adding your friends 3/8

var friends = {
    steve: {},
    bill: {}
};

iv. Adding properties 4/8

var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "(254) 555-5555"
        },
    steve: {
        firstName:"Steve",
        lastName:"Jobs",
        number: "(541) 555-5555"
        }
};

v. Tossing in an array 5/8

var friends = {
bill: {
    firstName: "Bill",
    lastName: "Gates",
    number: "(254) 555-5555",
    address: ['One Microsoft Way','Redmond','WA','98052']
    },
steve: {
    firstName:"Steve",
    lastName:"Jobs",
    number: "(541) 555-5555",
    address: ['TWo Apple Way','Redmond','CA','95014']
    }
};

vi. List ’em all! 6/8

var friends = {
bill: {
    firstName: "Bill",
    lastName: "Gates",
    number: "(254) 555-5555",
    address: ['One Microsoft Way','Redmond','WA','98052']
    },
steve: {
    firstName:"Steve",
    lastName:"Jobs",
    number: "(541) 555-5555",
    address: ['TWo Apple Way','Redmond','CA','95014']
    }
};

var list = function(friends) {
    for (key in friends) {
        console.log(key);
    };
};

vii. Search for a friend 7/8

var friends = {
bill: {
    firstName: "Bill",
    lastName: "Gates",
    number: "(254) 555-5555",
    address: ['One Microsoft Way','Redmond','WA','98052']
    },
steve: {
    firstName:"Steve",
    lastName:"Jobs",
    number: "(541) 555-5555",
    address: ['TWo Apple Way','Redmond','CA','95014']
    }
};

var list = function(friends) {
    for (key in friends) {
        console.log(key);
    };
};

var search = function(name) {
    for (var key in friends) {
        if(friends[key].firstName === name) {
            console.log(friends[key]);
            return friends[key];
            };
    };
};

search("Steve");

viii. Victory! 8/8
Save and Submit

Advertisements

One thought on “Contact List

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s