-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment9.html
More file actions
145 lines (138 loc) · 4.51 KB
/
Copy pathassignment9.html
File metadata and controls
145 lines (138 loc) · 4.51 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Library</title>
</head>
<body>
<h1>LIBRARY MANAGEMENT</h1>
<div id="line"></div><br>
<div id="line"></div>
<div id="inputs">
<div id="add_inpt">
<h2><b>Add Book</b></h2>
<input id="bkname" type="text">
<button onclick="add()">ADD</button>
<p id="status1"></p>
</div>
<div id="search_inpt">
<h2><b>Search Book</b></h2>
<input id="bksearch" type="text">
<button onclick="search()">SEARCH</button>
<p id="status2"></p>
</div>
</div>
<button onclick="record()">SEE ALL BOOKS</button>
<p id="all_books"></p>
<script>
let books = {};
function add(){
document.getElementById("all_books").innerHTML=" ";
document.getElementById("status2").innerHTML = " ";
let bk = document.getElementById("bkname").value;
if(bk==""){
document.getElementById("status1").innerHTML = " ";
alert("Enter a valid book name");
return;
}
let b = bk.toLowerCase();
let alrt = document.getElementById("status1");
if(b in books){
alrt.innerHTML = "...";
setTimeout(function(){
alrt.style.color="red";
alrt.innerHTML = "Book already in records";
},500)
}
else{
books[b]=bk;
alrt.innerHTML = "...";
alrt.style.color="green";
setTimeout(function(){
alrt.innerHTML = "Book added successfully";
},500)
}
console.log(books);
}
function search(){
document.getElementById("status1").innerHTML = " ";
document.getElementById("all_books").innerHTML= " ";
let bk = document.getElementById("bksearch").value;
if(bk==""){
document.getElementById("status2").innerHTML = " ";
alert("Enter a valid search key");
return;
}
let b = bk.toLowerCase();
const func=(bb)=>{
if(bb.includes(b)){
return books[bb];
}
}
let c = Object.keys(books);
res = c.filter(func);
if(res.length>0){
document.getElementById("status2").style.color = "green";
document.getElementById("status2").innerHTML = "...";
setTimeout(function(){
document.getElementById("status2").innerHTML = "The book(s) matching the search are:<br><b>"+res.join("<br>")+"</b>";
},500)
}
else{
document.getElementById("status2").style.color = "red";
document.getElementById("status2").innerHTML = "...";
setTimeout(function(){
document.getElementById("status2").innerHTML = "No match found";
},500)
}
}
function record(){
document.getElementById("status2").innerHTML = " ";
document.getElementById("status1").innerHTML = " ";
let c = Object.values(books);
if(c.length>0){
document.getElementById("all_books").innerHTML= c.join("<br>");
}
else{
document.getElementById("all_books").innerHTML= "Currently no books in library";
}
}
</script>
<style>
body{
text-align: center;
background-color: darkkhaki;
}
#line{
height:5px;
width: auto;
background-color: white;
}
h1{
margin: 5px;
padding: 1px;
font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;
font-size: 80px;
}
#inputs{
margin:40px;
display:flex;
justify-content: space-evenly;
}
input,
button{
height: 30px;
border: none;
border-radius: 5px;
}
#add_inpt,
#search_inpt{
text-align: center;
}
#status2{
justify-content: left;
}
</style>
</body>
</html>