Skip to content
Open
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
8bd778e
- change title.value to author.value.
HoussamLh Aug 18, 2025
bcdfde3
Merge branch 'CodeYourFuture:main' into feature/book-library
HoussamLh Aug 18, 2025
fff1b69
Merge branch 'CodeYourFuture:main' into feature/book-library
HoussamLh Sep 1, 2025
f439e87
Validate my HTML code online using W3.org
HoussamLh Sep 14, 2025
2537f48
Remove calling render() function to avoid duplicate
HoussamLh Sep 14, 2025
fd3649e
Fix the page number to passe and input as a number not as a string
HoussamLh Sep 14, 2025
94f7e3c
add a suffix like El and rename them to indicate DOM elements
HoussamLh Sep 14, 2025
b5a0f4b
Removes leading/trailing spaces and converts pages to a number and re…
HoussamLh Sep 15, 2025
b0c6627
Update to remove all rows at once and use innerText instead innerHTML
HoussamLh Sep 15, 2025
283fda2
Renamed submit() to submitBook() to avoid HTML form conflicts
HoussamLh Sep 15, 2025
b2a7d5e
fix: correct Book Library JS functionality
HoussamLh Sep 15, 2025
9adee93
add validation for page count input in Book Library
HoussamLh Sep 18, 2025
b16c7f2
Refactor table row creation to centralize cell creation and modulariz…
HoussamLh Sep 18, 2025
1de7803
update the render() function to delete just the the rows not the whol…
HoussamLh Sep 18, 2025
9b6df60
update the code to handle the toggle checkbox Read or Not Read
HoussamLh Sep 18, 2025
e953bb4
validate pages input to accept only positive whole numbers
HoussamLh Sep 19, 2025
25f7083
Refactor delete button to use index instead of book object
HoussamLh Sep 19, 2025
e5f6ec3
Refactor read/unread button creation to use a helper function
HoussamLh Sep 19, 2025
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
27 changes: 18 additions & 9 deletions debugging/book-library/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ function submit() {
alert("Please fill all fields!");
return false;
} else {
let book = new Book(title.value, title.value, pages.value, check.checked);
library.push(book);
//fix: change title.value to author.value
let book = new Book(title.value, author.value, pages.value, check.checked);
//Fix: change library.push(book) to myLibrary.push(book).
myLibrary.push(book);
render();
}
}
Expand All @@ -54,7 +56,9 @@ function render() {
let table = document.getElementById("display");
let rowsNumber = table.rows.length;
//delete old table
for (let n = rowsNumber - 1; n > 0; n-- {
// Fix : add a ) to the end of the for loop condition
// to avoid syntax error.
for (let n = rowsNumber - 1; n > 0; n--) {
table.deleteRow(n);
}
//insert updated row and cells
Expand All @@ -76,7 +80,9 @@ function render() {
changeBut.className = "btn btn-success";
wasReadCell.appendChild(changeBut);
let readStatus = "";
if (myLibrary[i].check == false) {
// Fix: change myLibrary[i].check to myLibrary[i].check == true
// to check if the book is read or not.
if (myLibrary[i].check == true) {
readStatus = "Yes";
} else {
readStatus = "No";
Expand All @@ -89,12 +95,15 @@ function render() {
});

//add delete button to every row and render again
// Fix :
// change delBut to delButton because we declare it.
// The event listener is "clicks" instead of "click".
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;
deleteCell.appendChild(delButton);
delButton.className = "btn btn-warning";
delButton.innerHTML = "Delete";
delButton.addEventListener("click", function () {
alert(`You've deleted title: ${myLibrary[i].title}`);
myLibrary.splice(i, 1);
render();
Expand Down