Skip to content

Commit 964dd83

Browse files
author
WolfNda
committed
Exercise 3
1 parent b54d97c commit 964dd83

10 files changed

+797
-89
lines changed
Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,35 @@
1-
var AddressBook = [];
1+
function AddressBook(){
2+
var contactList = [];
3+
this.addContact = function(contact){
4+
contactList.push(contact);
5+
};
6+
this.deleteContact = function(contact){
7+
var index = contactList.indexOf(contact);
8+
contactList.splice(index, 1);
9+
10+
};
11+
this.print = function(){
12+
console.log(contactList);
13+
};
14+
15+
this.Find = function(Needed){
16+
var answer = contactList.filter(function(x){
17+
18+
for(var field in x){
19+
20+
if(x[field] === Needed){
21+
return x[field];
22+
}
23+
}
24+
25+
});
26+
console.log(answer);
27+
};
28+
}
229

330
function Contact(firstName, lastName, cellProvider, cellNumber){
431
this.firstName = firstName;
532
this.lastName = lastName;
633
this.cellProvider = cellProvider;
7-
this.cellNumber = cellNumber;
8-
this.addToBook = function(){
9-
AddressBook.push(this);
10-
};
11-
this.deleteFromBook = function(){
12-
var index = AddressBook.indexOf(this);
13-
AddressBook.splice(index,index);
14-
};
34+
this.cellNumber = cellNumber;
1535
}
16-
17-
/* var filterednames = AddressBook.filter(function(obj) {
18-
if (obj.firstName === "Ndabenhle"){
19-
console.log(obj.cellNumber);
20-
}
21-
});
22-
*/
23-
24-
function findCellNumber(contactName){
25-
AddressBook.filter(function(obj){
26-
if(obj.firstName == contactName){
27-
return(obj.cellNumber);
28-
}
29-
}
30-
);
31-
}
32-
33-
34-
var nda = new Contact("Ndabenhle", "Ngulube", "Vodacom", "0798900606");
35-
var nhla = new Contact("Nhlanhla", "Ngulube", "MTN", "0798900607");
36-
var thomas = new Contact("Thomas","Razuko", "CellC", "0832546071");
37-
nda.addToBook();
38-
nhla.addToBook();
39-
thomas.addToBook();
40-
console.log(AddressBook);
41-
console.log()
42-
thomas.deleteFromBook();
43-
console.log(AddressBook);
44-
45-
findCellNumber("Ndabenhle");
Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,35 @@
1-
var AddressBook = [];
1+
function AddressBook(){
2+
var contactList = [];
3+
this.addContact = function(contact){
4+
contactList.push(contact);
5+
};
6+
this.deleteContact = function(contact){
7+
var index = contactList.indexOf(contact);
8+
contactList.splice(index, 1);
9+
10+
};
11+
this.print = function(){
12+
console.log(contactList);
13+
};
14+
15+
this.Find = function(Needed){
16+
var answer = contactList.filter(function(x){
17+
18+
for(var field in x){
19+
20+
if(x[field] === Needed){
21+
return x[field];
22+
}
23+
}
24+
25+
});
26+
console.log(answer);
27+
};
28+
}
229

330
function Contact(firstName, lastName, cellProvider, cellNumber){
431
this.firstName = firstName;
532
this.lastName = lastName;
633
this.cellProvider = cellProvider;
7-
this.cellNumber = cellNumber;
8-
this.addToBook = function(){
9-
AddressBook.push(this);
10-
};
11-
this.deleteFromBook = function(){
12-
var index = AddressBook.indexOf(this);
13-
AddressBook.splice(index,index);
14-
};
34+
this.cellNumber = cellNumber;
1535
}
16-
17-
/* var filterednames = AddressBook.filter(function(obj) {
18-
if (obj.firstName === "Ndabenhle"){
19-
console.log(obj.cellNumber);
20-
}
21-
});
22-
*/
23-
24-
function findCellNumber(contactName){
25-
AddressBook.filter(function(obj){
26-
if(obj.firstName == contactName){
27-
return(obj.cellNumber);
28-
}
29-
}
30-
);
31-
}
32-
33-
34-
var nda = new Contact("Ndabenhle", "Ngulube", "Vodacom", "0798900606");
35-
var nhla = new Contact("Nhlanhla", "Ngulube", "MTN", "0798900607");
36-
var thomas = new Contact("Thomas","Razuko", "CellC", "0832546071");
37-
nda.addToBook();
38-
nhla.addToBook();
39-
thomas.addToBook();
40-
console.log(AddressBook);
41-
console.log()
42-
thomas.deleteFromBook();
43-
console.log(AddressBook);
44-
45-
findCellNumber("Ndabenhle");

ExerciseThree/UserInterface.css

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#container {
2+
3+
height: 520px;
4+
width: 500px;
5+
border: 1px solid orange;
6+
background-color: orange;
7+
border-radius: 15px;
8+
9+
}
10+
11+
#searchBox {
12+
13+
height: 140px;
14+
width: 450px;
15+
border: 2px solid #FF4500;
16+
border-radius: 15px;
17+
margin-top: 20px;
18+
background-color: #FF4500;
19+
}
20+
21+
#numbers {
22+
23+
height: 250px;
24+
width: 300px;
25+
//border: 1px solid black;
26+
//background-color: #EC9242;
27+
28+
}
29+
30+
#numbers2 {
31+
32+
height: 250px;
33+
width: 300px;
34+
//border: 1px solid green;
35+
//background-color: #EC9242;
36+
37+
}
38+
39+
.inputs {
40+
border-radius: 5px;
41+
height: 20px;
42+
border: 2px solid #FF8C00;
43+
padding: 2px;
44+
45+
46+
}
47+
48+
.inputs2 {
49+
border-radius: 5px;
50+
height: 20px;
51+
border: 2px solid red;
52+
padding: 2px;
53+
54+
55+
}
56+
57+
#add {
58+
59+
border-radius: 5px;
60+
height: 30px;
61+
width: 90px;
62+
#border: 2px solid #FF8C00;
63+
padding: 2px;
64+
font-family: "Helvetica";
65+
}
66+
67+
h1, h3 {
68+
font-family: "Helvetica";
69+
}
70+
71+
.AddedContacts {
72+
border: 1px solid #FF4400;
73+
margin-bottom: 5px;
74+
75+
}
76+
77+
.AddedContacts:hover{
78+
background-color: yellow;
79+
}

ExerciseThree/UserInterface.css~

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#container {
2+
3+
height: 520px;
4+
width: 500px;
5+
border: 1px solid orange;
6+
background-color: orange;
7+
border-radius: 15px;
8+
9+
}
10+
11+
#searchBox {
12+
13+
height: 140px;
14+
width: 450px;
15+
border: 2px solid #FF4500;
16+
border-radius: 15px;
17+
margin-top: 20px;
18+
background-color: #FF4500;
19+
}
20+
21+
#numbers {
22+
23+
height: 250px;
24+
width: 300px;
25+
//border: 1px solid black;
26+
//background-color: #EC9242;
27+
28+
}
29+
30+
#numbers2 {
31+
32+
height: 250px;
33+
width: 300px;
34+
//border: 1px solid black;
35+
//background-color: #EC9242;
36+
37+
}
38+
39+
.inputs {
40+
border-radius: 5px;
41+
height: 20px;
42+
border: 2px solid #FF8C00;
43+
padding: 2px;
44+
45+
46+
}
47+
48+
.inputs2 {
49+
border-radius: 5px;
50+
height: 20px;
51+
border: 2px solid red;
52+
padding: 2px;
53+
54+
55+
}
56+
57+
#add {
58+
59+
border-radius: 5px;
60+
height: 30px;
61+
width: 90px;
62+
#border: 2px solid #FF8C00;
63+
padding: 2px;
64+
font-family: "Helvetica";
65+
}
66+
67+
h1, h3 {
68+
font-family: "Helvetica";
69+
}
70+
71+
.AddedContacts {
72+
border: 1px solid #FF4400;
73+
margin-bottom: 5px;
74+
75+
}
76+
77+
.AddedContacts:hover{
78+
background-color: yellow;
79+
}

ExerciseThree/UserInterface.html

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
5+
6+
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
7+
8+
<meta charset="utf-8">
9+
<title>Addy Book</title>
10+
11+
<script type="text/javascript" src="UserInterface.js"></script>
12+
13+
<link rel="stylesheet" type="text/css" href="UserInterface.css">
14+
</head>
15+
<body>
16+
<center>
17+
<div id="container">
18+
<center><h1>My Address Book </h1></center>
19+
<br>
20+
<center>
21+
22+
First Name:<input type="text" name="firstname" placeholder="Enter First Name here" id="firstname" class="inputs" /><br><br>
23+
Last Name:<input type="text" name="lastname" placeholder="Enter Last Name here" id="lastname" class="inputs" /><br><br>
24+
Cell Provider<input type="text" name="cellprovider" placeholder="Enter Cell Provider here" id="cellprovider" class="inputs" /><br><br>
25+
Cell Number:<input type="text" name="cellnumber" placeholder="Enter Cell Number here" id="cellnumber" class="inputs" /><br><br>
26+
27+
<button type="submit" value="Submit" id="add">Submit</button>
28+
29+
</center>
30+
31+
<center>
32+
<div id="searchBox">
33+
<center><h3>Search</h3></center>
34+
35+
36+
<input type="text" name="search" id="search" class="inputs"/>
37+
<button type="submit" value="search" id="RunSearch">Search</button>
38+
<button type="submit" value="refresh" id="refresh">Refresh</button>
39+
40+
41+
42+
<br>
43+
<div id="boundary">
44+
<div id="numbers">
45+
46+
47+
48+
</div>
49+
<div id ="numbers2">
50+
51+
</div>
52+
53+
</div>
54+
</div>
55+
</center>
56+
57+
</div>
58+
</center>
59+
</body>
60+
</html>

0 commit comments

Comments
 (0)