Skip to content

Commit 7f7a3ca

Browse files
Add book-library files to clean branch
1 parent 3a422e9 commit 7f7a3ca

2 files changed

Lines changed: 17 additions & 15 deletions

File tree

debugging/book-library/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ <h1>Library</h1>
6565
type="submit"
6666
value="Submit"
6767
class="btn btn-primary"
68-
onclick="submit();"
68+
onclick="addBook();"
6969
/>
7070
</div>
7171
</div>
@@ -77,7 +77,7 @@ <h1>Library</h1>
7777
<th>Author</th>
7878
<th>Number of Pages</th>
7979
<th>Read</th>
80-
<th></th>
80+
<th>Delete</th>
8181
</tr>
8282
</thead>
8383
<tbody>

debugging/book-library/script.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function populateStorage() {
1616
);
1717
myLibrary.push(book1);
1818
myLibrary.push(book2);
19-
render();
19+
2020
}
2121
}
2222

@@ -27,18 +27,20 @@ const check = document.getElementById("check");
2727

2828
//check the right input from forms and if its ok -> add the new book (object in array)
2929
//via Book function and start render function
30-
function submit() {
30+
function addBook() {
3131
if (
3232
title.value == null ||
3333
title.value == "" ||
3434
pages.value == null ||
35-
pages.value == ""
35+
pages.value == "" ||
36+
author.value == null ||
37+
author.value == ""
3638
) {
3739
alert("Please fill all fields!");
3840
return false;
3941
} else {
40-
let book = new Book(title.value, title.value, pages.value, check.checked);
41-
library.push(book);
42+
let book = new Book(title.value, author.value, pages.value, check.checked);
43+
myLibrary.push(book);
4244
render();
4345
}
4446
}
@@ -54,7 +56,7 @@ function render() {
5456
let table = document.getElementById("display");
5557
let rowsNumber = table.rows.length;
5658
//delete old table
57-
for (let n = rowsNumber - 1; n > 0; n-- {
59+
for (let n = rowsNumber - 1; n > 0; n-- ){
5860
table.deleteRow(n);
5961
}
6062
//insert updated row and cells
@@ -69,14 +71,14 @@ function render() {
6971
titleCell.innerHTML = myLibrary[i].title;
7072
authorCell.innerHTML = myLibrary[i].author;
7173
pagesCell.innerHTML = myLibrary[i].pages;
72-
74+
7375
//add and wait for action for read/unread button
7476
let changeBut = document.createElement("button");
7577
changeBut.id = i;
7678
changeBut.className = "btn btn-success";
7779
wasReadCell.appendChild(changeBut);
7880
let readStatus = "";
79-
if (myLibrary[i].check == false) {
81+
if (myLibrary[i].check == true) {
8082
readStatus = "Yes";
8183
} else {
8284
readStatus = "No";
@@ -90,11 +92,11 @@ function render() {
9092

9193
//add delete button to every row and render again
9294
let delButton = document.createElement("button");
93-
delBut.id = i + 5;
94-
deleteCell.appendChild(delBut);
95-
delBut.className = "btn btn-warning";
96-
delBut.innerHTML = "Delete";
97-
delBut.addEventListener("clicks", function () {
95+
delButton.id = i;
96+
deleteCell.appendChild(delButton);
97+
delButton.className = "btn btn-warning";
98+
delButton.innerHTML = "Delete";
99+
delButton.addEventListener("click", function () {
98100
alert(`You've deleted title: ${myLibrary[i].title}`);
99101
myLibrary.splice(i, 1);
100102
render();

0 commit comments

Comments
 (0)