Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions debugging/book-library/debugging-notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# HTML Debugging Checklist

## Page Structure

## Book Input Form

## Add Book Button

## Book Display Area

## Delete Functionality

## Read Status

## Validation Support

## Browser Testing


# JavaScript Debugging Checklist

## Library Data Storage

## Page Loading

## Add Book Function

## Book Constructor

## Render Function

## Read/Unread Button

## Delete Button

## Console Errors


## Final Testing
- [ ] Add a book with all information
- [ ] Add a book without title
- [ ] Add a book without author
- [ ] Add a book without pages
- [ ] Add a read book
- [ ] Add an unread book
- [ ] Delete a book
- [ ] Change read/unread status

# HTML correction:
- input type
- submit function
-
# Script.js correction:
- delete e from addEventListener
- correct book name
- add input validation for author value in submit() function
- add author.value replacing title.value in new Book()
- replace library by myLibrary
- correct check == true/false and made correction for readstatus = yes/no for read button
- correct variable name delBut > delButton
- correct clicks > click
4 changes: 2 additions & 2 deletions debugging/book-library/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ <h1>Library</h1>
<div class="form-group">
<label for="title">Title:</label>
<input
type="title"
type="text"
class="form-control"
id="title"
name="title"
required
/>
<label for="author">Author: </label>
<input
type="author"
type="text"
class="form-control"
id="author"
name="author"
Expand Down
30 changes: 19 additions & 11 deletions debugging/book-library/script.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
let myLibrary = [];

window.addEventListener("load", function (e) {
window.addEventListener("load", function () {
//delete e as it is never used
populateStorage();
render();
});

function populateStorage() {
if (myLibrary.length == 0) {
let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true);
let book1 = new Book("Robinson Crusoe", "Daniel Defoe", "252", true); //correct book name
let book2 = new Book(
"The Old Man and the Sea",
"Ernest Hemingway",
Expand All @@ -31,14 +32,17 @@ function submit() {
if (
title.value == null ||
title.value == "" ||
author.value == null || //need input validation for author value, added this
author.value == "" ||
pages.value == null ||
pages.value == ""
) {
alert("Please fill all fields!");
return false;
} else {
let book = new Book(title.value, title.value, pages.value, check.checked);
library.push(book);
let book = new Book(title.value, author.value, pages.value, check.checked); //added author.value by
// replacing 2nd title.value to author.value
myLibrary.push(book); //corrected name for original array library > myLibrary
render();
}
}
Expand All @@ -54,7 +58,7 @@ function render() {
let table = document.getElementById("display");
let rowsNumber = table.rows.length;
//delete old table
for (let n = rowsNumber - 1; n > 0; n-- {
for (let n = rowsNumber - 1; n > 0; n--) {
table.deleteRow(n);
}
//insert updated row and cells
Expand All @@ -76,7 +80,10 @@ function render() {
changeBut.className = "btn btn-success";
wasReadCell.appendChild(changeBut);
let readStatus = "";
if (myLibrary[i].check == false) {
if (myLibrary[i].check == true) {
// correct for read button, if user checks reads,
// it sould be check == true & button shows yes, but previuos it was false > yes, ture > no, means
// reverse
readStatus = "Yes";
} else {
readStatus = "No";
Expand All @@ -90,11 +97,12 @@ function render() {

//add delete button to every row and render again
let delButton = document.createElement("button");
delBut.id = i + 5;
deleteCell.appendChild(delBut);
delBut.className = "btn btn-warning";
delBut.innerHTML = "Delete";
delBut.addEventListener("clicks", function () {
delButton.id = i + 5; // correct variable name delBut > delButton
deleteCell.appendChild(delButton);
delButton.className = "btn btn-warning";
delButton.innerHTML = "Delete";
delButton.addEventListener("click", function () {
// correct clicks > click
alert(`You've deleted title: ${myLibrary[i].title}`);
myLibrary.splice(i, 1);
render();
Expand Down
Loading