-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.js
97 lines (77 loc) · 2.5 KB
/
data.js
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
// Library creation
class Library {
// books Collection
constructor() {
this.books = [];
}
// book adding function
addBook(book) {
this.books.push(book)
}
getBook() {
return this.books;
}
getBookCount() {
return this.books.length
}
remove(index){
this.books.splice(index,1)
getLibrarydata()
}
}
////////////////////////////////////////////////////////
// book creation
class Book {
constructor(title, author) {
this.bookTitle = title;
this.bookAuthor = author;
}
};
// Library calling variable
const lib = new Library();
//////////////////////////////////////////////////////////
// form submit function and adding input and etc..
const formEl = document.querySelector("form");
formEl.addEventListener("submit", (event) => {
event.preventDefault();
const titleIN = document.querySelector("#booktitle").value;
const authorIN = document.querySelector("#bookauthor").value;
if (titleIN && authorIN) {
const book = new Book(titleIN, authorIN);
lib.addBook(book);
}
// geting books and list outin ui
getLibrarydata()
document.querySelector("#booktitle").value = "";
document.querySelector("#bookauthor").value = "";
});
//////////////////////////////////////////////////////////////
/// adding function Mark As Read
const resultEL = document.querySelector(".result");
function markAsRead(index) {
const read = resultEL.children[index];
read.style.textDecoration = "line-through solid gray";
}
////////////////////////////////////////////////////////////
// Removeing function
function remove(index) {
lib.remove(index)
}
///////////////////////////////////////////////////////////
// Adding list in ui
function getLibrarydata() {
const resultEL = document.querySelector(".result");
const countEl = document.querySelector(".bookCount");
const viewEl = document.querySelector(".footer")
countEl.textContent = lib.getBookCount();
if(lib.getBookCount() === 0){
viewEl.style.display = "none"
}else{
viewEl.style.display = "block";
}
resultEL.innerHTML =""
lib.getBook().forEach((book,index) => {
resultEL.innerHTML += `<li>${book.bookTitle} by ${book.bookAuthor} <button class="Read" onClick="markAsRead(${index})">Mark as Read</button><button class="Remove" onClick="remove(${index})">Remove</button></li>`
})
}
//////////////////////////xxxxxxx///////////////////////////////