-
Notifications
You must be signed in to change notification settings - Fork 0
/
phonebook.html
114 lines (79 loc) · 2.18 KB
/
phonebook.html
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<html>
<head>
<title>Simple Contact List</title>
</style>
</head>
<body>
<script type="text/javascript">
var bob = {
firstName: "Bob",
lastName: "Bullock",
phoneNumber: "(650) 899 - 9918",
email: "[email protected]"
};
var mary = {
firstName: "Mary",
lastName: "Johnson",
phoneNumber: "(650) 888 - 8888",
email: "[email protected]"
};
var jorge = {
firstName: "Jorge",
lastName: "Polanco",
phoneNumber: "(201) 928 - 8008",
email: "[email protected]"
};
// THE CONTACT LIST
// ****************
var contacts = [];
contacts[0] = bob;
contacts[1] = mary;
contacts[2] = jorge;
console.log(contacts);
console.log(contacts[1].phoneNumber);
// PRINT ONE ENTRY
// ***************
var printPerson = function (person) {
console.log(person.firstName + " " + person.lastName);
}
printPerson(bob);
// PRINT EMAIL LIST
// ****************
for(var x = 0; x < contacts.length; x++) {
console.log(contacts[x].email);
};
// PRINT CONTACT LIST
// ******************
function list() {
for(var i = 0; i < contacts.length; i++) {
console.log(contacts[i]);
}
}
list();
// FIND ENTRY BY LAST NAME
// *****************
var search = function (lastName) {
var contactsLength = contacts.length;
for(var j = 0; j < contactsLength; j++) {
if (contacts[j].lastName === lastName) {
printPerson(contacts[j]);
}
}
}
search("Polanco");
// ADD NEW ENTRY
// *************
var addEntry = function(firstName, lastName, phoneNumber, email) {
contacts[contacts.length] = {
firstName: firstName,
lastName: lastName,
phoneNumber: phoneNumber,
email: email
}
}
addEntry("Victoria", "Smith", "(512) 234 - 9384", "[email protected]");
contacts;
contacts[3];
</script>
</body>
</html>