Created
April 12, 2012 22:09
-
-
Save Jared-Prime/2371377 to your computer and use it in GitHub Desktop.
Address Book - using objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Codeacademy.com project, "Address Book" | |
// the functions input and output information about objects collected in the array. | |
// Note that there's no class; you have to define the attributes explicitly when creating the object. | |
var contacts = []; | |
function printPerson (person) { | |
console.log(person.firstName + " " + person.lastName); | |
} | |
function list() { | |
var items = contacts.length; | |
for (i=0;i<items;i++) { | |
printPerson(contacts[i]); | |
} | |
} | |
function add(firstName,lastName,email,telephone){ | |
var friend = { | |
firstName: firstName, | |
lastName: lastName, | |
phoneNumber: telephone, | |
email: email | |
}; | |
contacts[contacts.length] = friend; | |
} | |
function search(lastName) { | |
var items = contacts.length; | |
for(i=0;i<items;i++) { | |
if(lastName===contacts[i].lastName){ | |
printPerson(contacts[i]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment