Skip to content

Commit 956cf0e

Browse files
committed
fix book library app bugs
1 parent 3a422e9 commit 956cf0e

3 files changed

Lines changed: 82 additions & 13 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# HTML Debugging Checklist
2+
3+
## Page Structure
4+
5+
## Book Input Form
6+
7+
## Add Book Button
8+
9+
## Book Display Area
10+
11+
## Delete Functionality
12+
13+
## Read Status
14+
15+
## Validation Support
16+
17+
## Browser Testing
18+
19+
20+
# JavaScript Debugging Checklist
21+
22+
## Library Data Storage
23+
24+
## Page Loading
25+
26+
## Add Book Function
27+
28+
## Book Constructor
29+
30+
## Render Function
31+
32+
## Read/Unread Button
33+
34+
## Delete Button
35+
36+
## Console Errors
37+
38+
39+
## Final Testing
40+
- [ ] Add a book with all information
41+
- [ ] Add a book without title
42+
- [ ] Add a book without author
43+
- [ ] Add a book without pages
44+
- [ ] Add a read book
45+
- [ ] Add an unread book
46+
- [ ] Delete a book
47+
- [ ] Change read/unread status
48+
49+
# HTML correction:
50+
- input type
51+
- submit function
52+
-
53+
# Script.js correction:
54+
- delete e from addEventListener
55+
- correct book name
56+
- add input validation for author value in submit() function
57+
- add author.value replacing title.value in new Book()
58+
- replace library by myLibrary
59+
- correct check == true/false and made correction for readstatus = yes/no for read button
60+
- correct variable name delBut > delButton
61+
- correct clicks > click

‎debugging/book-library/index.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ <h1>Library</h1>
3131
<div class="form-group">
3232
<label for="title">Title:</label>
3333
<input
34-
type="title"
34+
type="text"
3535
class="form-control"
3636
id="title"
3737
name="title"
3838
required
3939
/>
4040
<label for="author">Author: </label>
4141
<input
42-
type="author"
42+
type="text"
4343
class="form-control"
4444
id="author"
4545
name="author"

‎debugging/book-library/script.js‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
let myLibrary = [];
22

3-
window.addEventListener("load", function (e) {
3+
window.addEventListener("load", function () {
4+
//delete e as it is never used
45
populateStorage();
56
render();
67
});
78

89
function populateStorage() {
910
if (myLibrary.length == 0) {
10-
let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true);
11+
let book1 = new Book("Robinson Crusoe", "Daniel Defoe", "252", true); //correct book name
1112
let book2 = new Book(
1213
"The Old Man and the Sea",
1314
"Ernest Hemingway",
@@ -31,14 +32,17 @@ function submit() {
3132
if (
3233
title.value == null ||
3334
title.value == "" ||
35+
author.value == null || //need input validation for author value, added this
36+
author.value == "" ||
3437
pages.value == null ||
3538
pages.value == ""
3639
) {
3740
alert("Please fill all fields!");
3841
return false;
3942
} else {
40-
let book = new Book(title.value, title.value, pages.value, check.checked);
41-
library.push(book);
43+
let book = new Book(title.value, author.value, pages.value, check.checked); //added author.value by
44+
// replacing 2nd title.value to author.value
45+
myLibrary.push(book); //corrected name for original array library > myLibrary
4246
render();
4347
}
4448
}
@@ -54,7 +58,7 @@ function render() {
5458
let table = document.getElementById("display");
5559
let rowsNumber = table.rows.length;
5660
//delete old table
57-
for (let n = rowsNumber - 1; n > 0; n-- {
61+
for (let n = rowsNumber - 1; n > 0; n--) {
5862
table.deleteRow(n);
5963
}
6064
//insert updated row and cells
@@ -76,7 +80,10 @@ function render() {
7680
changeBut.className = "btn btn-success";
7781
wasReadCell.appendChild(changeBut);
7882
let readStatus = "";
79-
if (myLibrary[i].check == false) {
83+
if (myLibrary[i].check == true) {
84+
// correct for read button, if user checks reads,
85+
// it sould be check == true & button shows yes, but previuos it was false > yes, ture > no, means
86+
// reverse
8087
readStatus = "Yes";
8188
} else {
8289
readStatus = "No";
@@ -90,11 +97,12 @@ function render() {
9097

9198
//add delete button to every row and render again
9299
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 () {
100+
delButton.id = i + 5; // correct variable name delBut > delButton
101+
deleteCell.appendChild(delButton);
102+
delButton.className = "btn btn-warning";
103+
delButton.innerHTML = "Delete";
104+
delButton.addEventListener("click", function () {
105+
// correct clicks > click
98106
alert(`You've deleted title: ${myLibrary[i].title}`);
99107
myLibrary.splice(i, 1);
100108
render();

0 commit comments

Comments
 (0)