-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddressBook.js
More file actions
57 lines (44 loc) · 1.2 KB
/
addressBook.js
File metadata and controls
57 lines (44 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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 contactsLength = contacts.length;
for (var i = 0; i < contactsLength; i++) {
printPerson(contacts[i]);
}
}
/*Create a search function
then call it passing "Jones"*/
function search(lastName){
contactsLength = contacts.length;
for(var x = 0 ; x<contactsLength;x++){
if(contacts[x].lastName === lastName){
printPerson(contacts[x]);
}
};
};
search("Jones");
function add(firstName,lastName,email,phoneNumber){
var newContact = new Object();
contacts[contacts.length] = newContact;
// all without this
newContact.firstName = firstName;
newContact.lastName = lastName;
newContact.email = email;
newContact.phoneNumber = phoneNumber;
};
add("Alvaro","Mesa","alvaromesa19@gmail.com","(999)999-9999");
list();