var bob = {
firstName: "Bob",
lastName: "Jones",
phoneNumber: "(650) 777 - 7777",
email: "bob.jones@example.com"
};
var mary = {
firstName: "Mary",
lastName: "Johnson",
phoneNumber: "(650) 888 - 8888",
email: "mary.johnson@example.com"
};
var contacts = [bob, mary];
function printPerson (person) {
console.log(person.firstName + " " + person.lastName);
}
function list() {
var items = contacts.length;
var i;
for (i=0; i<items; i++){
printPerson(contacts[i]);
}
}
list();
function search(lastName) {
var items = contacts.length;
var i;
for (i=0; i<items; i++) {
if (contacts[i].lastName === lastName) {
printPerson(contacts[i]);
}
}
}
search("Jones");
function add(firstName, lastName, email, telephone) {
var newPerson = {firstName : this.firstName,
lastName : this.lastName,
phoneNumber : this.telephone,
email : this.email};
contacts[contacts.length] = newPerson;
}
var firstName = prompt("Enter first name");
var lastName = prompt("Enter last name");
var email = prompt("Enter email");
var telephone = prompt("Enter phone number");
add(firstName, lastName, email, telephone);