-
Notifications
You must be signed in to change notification settings - Fork 0
/
task4(phoneBook).html
56 lines (53 loc) · 1.66 KB
/
task4(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
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Page Title</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<script>
var contacts = [
{
name:"Esraa",
phone:"01113375563"
}
];
function addNewContact(){
var newContact = {};
newContact.name = prompt("enter contact name");
newContact.phone = prompt("enter contact phone");
contacts.push(newContact);
}
function searchForContact(){
var searchKeyword = prompt("enter name or phone")
for(var i =0;i<contacts.length;i++){
var currentContact = contacts[i];
if(searchKeyword == currentContact.name || searchKeyword == currentContact.phone){
alert("name = "+currentContact.name +" & phone = "+currentContact.phone);
break;
}
}
}
function runPhoneBook(){
var stop = false;
do{
var op = prompt("what do you want (add,search,exit)");
switch(op){
case "add":
addNewContact();
break;
case "search":
searchForContact();
break;
case "exit":
stop = true;
break;
}
}while(!stop)
}
runPhoneBook();
</script>
</head>
<body>
</body>
</html>