Skip to content

Instantly share code, notes, and snippets.

@nola
Forked from keeganbrown/A-Pen-by-Keegan-Brown.markdown
Last active January 3, 2016 06:19

Revisions

  1. nola revised this gist Feb 10, 2014. 2 changed files with 1 addition and 10 deletions.
    7 changes: 0 additions & 7 deletions A-Pen-by-Keegan-Brown.markdown
    Original file line number Diff line number Diff line change
    @@ -1,7 +0,0 @@
    A Pen by Keegan Brown
    ---------------------


    A [Pen](http://codepen.io/keeganbrown/pen/lCnBf) by [Keegan Brown](http://codepen.io/keeganbrown) on [CodePen](http://codepen.io/).

    [License](http://codepen.io/keeganbrown/pen/lCnBf/license).
    4 changes: 1 addition & 3 deletions script.js
    Original file line number Diff line number Diff line change
    @@ -7,11 +7,9 @@ var Friend = function ( config ) {
    this.number = config.number;
    this.address = config.address;
    this.email = config.email;

    this.getMyFullName = function () {
    logger( this.firstName + " " + this.lastName );
    }

    };
    this.getMyFullName();
    }

  2. @keeganbrown keeganbrown created this gist Jan 14, 2014.
    7 changes: 7 additions & 0 deletions A-Pen-by-Keegan-Brown.markdown
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    A Pen by Keegan Brown
    ---------------------


    A [Pen](http://codepen.io/keeganbrown/pen/lCnBf) by [Keegan Brown](http://codepen.io/keeganbrown) on [CodePen](http://codepen.io/).

    [License](http://codepen.io/keeganbrown/pen/lCnBf/license).
    1 change: 1 addition & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    <div id="output"></div>
    76 changes: 76 additions & 0 deletions script.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,76 @@
    //create an object
    var friends = {};

    var Friend = function ( config ) {
    this.firstName = config.firstName;
    this.lastName = config.lastName;
    this.number = config.number;
    this.address = config.address;
    this.email = config.email;

    this.getMyFullName = function () {
    logger( this.firstName + " " + this.lastName );
    }

    this.getMyFullName();
    }

    //add people to it
    friends.bill = new Friend({ //observe this declaration as bill is an object of friends
    firstName: "Bill",
    lastName: "Gates",
    number: "(206) 555-5555",
    address: ['One Microsoft Way','Redmond','WA','98052']
    });

    //add another
    friends.steve = new Friend({
    firstName: "Steve",
    lastName: "Jobs",
    number: "(408) 555-5555",
    address: ['1 Infinite Loop','Cupertino','CA','95014']
    });

    //log out all contents of the object
    function list (obj) {
    for(var prop in obj) {
    logger(prop);
    }
    };

    //search for "steve"
    function search (name) {
    for(var prop in friends) {
    if(friends[prop].firstName === name) {
    logger(friends[prop]);
    return friends[prop];
    }
    }
    };

    function add (firstName, lastName, phoneNumber, email){
    friends[ firstName.toLowerCase() ] = new Friend({
    firstName: firstName,
    lastName: lastName,
    number: phoneNumber,
    email: email
    });
    }

    function logger () {
    for ( var i in arguments ) {
    document.getElementById("output").innerHTML += "<br>"+ arguments[i];
    console.log(arguments[i]);
    }
    }

    add("Cyril", "Celestine", "5042282838", "[email protected]");
    list(friends);
    var tmp = search("Cyril");



    console.log(friends);


    tmp.getMyFullName();