From 36a742ac3f430c65b40d46f8d6e5f76128fda198 Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Thu, 14 May 2026 05:08:36 +0100 Subject: [PATCH 1/6] fixed bugs --- debugging/book-library/index.html | 143 ++++++++++++------------------ debugging/book-library/script.js | 12 +-- 2 files changed, 61 insertions(+), 94 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71..0fb3eda6 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,96 +1,63 @@ - - - - - - - - - - -
-

Library

-

Add books to your virtual library

-
+ + + + + + + + + + + +
+

Library

+

Add books to your virtual library

+
- + -
-
- - - - - - - - -
+
+
+ + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + +
TitleAuthorNumber of PagesRead
- - - - - - - - - - - - - - - - - - - -
TitleAuthorNumber of PagesRead
+ + - - - + \ No newline at end of file diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d..12192926 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -37,8 +37,8 @@ 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); + let book = new Book(title.value, author.value, pages.value, check.checked); + myLibrary.push(book); render(); } } @@ -54,7 +54,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 @@ -76,7 +76,7 @@ function render() { changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); let readStatus = ""; - if (myLibrary[i].check == false) { + if (myLibrary[i].check == true) { readStatus = "Yes"; } else { readStatus = "No"; @@ -89,12 +89,12 @@ function render() { }); //add delete button to every row and render again - let delButton = document.createElement("button"); + let delBut = document.createElement("button"); delBut.id = i + 5; deleteCell.appendChild(delBut); delBut.className = "btn btn-warning"; delBut.innerHTML = "Delete"; - delBut.addEventListener("clicks", function () { + delBut.addEventListener("click", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); From cf4e2c309c226434707ec3f02e29cd9b107315dd Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Thu, 14 May 2026 21:23:07 +0100 Subject: [PATCH 2/6] fixed bugs from validator.w3 - passed --- debugging/book-library/index.html | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 0fb3eda6..c97cf500 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,14 +1,14 @@ - + - - + Book Library + - - + + @@ -24,15 +24,15 @@

Library

- + - + - + - +
From 3d2a92244e8bf7818780bf3703f046f69e94ce45 Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Thu, 14 May 2026 21:29:22 +0100 Subject: [PATCH 3/6] removed render() running twice --- debugging/book-library/index.html | 2 +- debugging/book-library/script.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index c97cf500..7035efa1 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -57,7 +57,7 @@

Library

- + \ No newline at end of file diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 12192926..17fa86fd 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -2,7 +2,6 @@ let myLibrary = []; window.addEventListener("load", function (e) { populateStorage(); - render(); }); function populateStorage() { From 0f5279bf5a963aca8712479e6a7b35965d9d5e0f Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Fri, 15 May 2026 03:02:42 +0100 Subject: [PATCH 4/6] index updated --- debugging/book-library/index.html | 22 ++++++++++++++-------- debugging/book-library/script.js | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 7035efa1..66d41526 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,14 +1,15 @@ - + Book Library + - + @@ -24,15 +25,20 @@

Library

- - - + + + + + + + - + +
@@ -57,7 +63,7 @@

Library

- + \ No newline at end of file diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 17fa86fd..33ef565e 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -26,7 +26,7 @@ const check = document.getElementById("check"); //check the right input from forms and if its ok -> add the new book (object in array) //via Book function and start render function -function submit() { +function addBook() { if ( title.value == null || title.value == "" || From 438cc21db31d2c0c789b95a59fcc91f5d725698c Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Fri, 15 May 2026 04:00:35 +0100 Subject: [PATCH 5/6] all changes made --- debugging/book-library/index.html | 11 ++-- debugging/book-library/script.js | 86 +++++++++++++++---------------- debugging/book-library/style.css | 2 +- 3 files changed, 46 insertions(+), 53 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 66d41526..3f2fe9c3 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -38,7 +38,7 @@

Library

Read - +
@@ -52,18 +52,13 @@

Library

- + - - - - - - + \ No newline at end of file diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 33ef565e..faf667c1 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -6,8 +6,8 @@ window.addEventListener("load", function (e) { function populateStorage() { if (myLibrary.length == 0) { - let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true); - let book2 = new Book( + const book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true); + const book2 = new Book( "The Old Man and the Sea", "Ernest Hemingway", "127", @@ -19,27 +19,30 @@ function populateStorage() { } } -const title = document.getElementById("title"); -const author = document.getElementById("author"); -const pages = document.getElementById("pages"); -const check = document.getElementById("check"); +const titleInput = document.getElementById("title"); +const authorInput = document.getElementById("author"); +const pagesInput = document.getElementById("pages"); +const checkInput = document.getElementById("check"); //check the right input from forms and if its ok -> add the new book (object in array) //via Book function and start render function function addBook() { if ( - title.value == null || - title.value == "" || - pages.value == null || - pages.value == "" + titleInput.value.trim() == "" || + pagesInput.value.trim() == "" || + Number(pagesInput.value) < 1 ) { alert("Please fill all fields!"); return false; - } else { - let book = new Book(title.value, author.value, pages.value, check.checked); - myLibrary.push(book); - render(); } + const book = new Book( + titleInput.value.trim(), + authorInput.value.trim(), + Number(pagesInput.value), + checkInput.checked + ); + myLibrary.push(book); + render(); } function Book(title, author, pages, check) { @@ -50,53 +53,48 @@ function Book(title, author, pages, check) { } function render() { - let table = document.getElementById("display"); - let rowsNumber = table.rows.length; + const table = document.getElementById("display"); + const tableBody = document.querySelector("#display tbody"); + //delete old table - for (let n = rowsNumber - 1; n > 0; n--) { - table.deleteRow(n); - } - //insert updated row and cells + tableBody.innerHTML = ""; + let length = myLibrary.length; for (let i = 0; i < length; i++) { - let row = table.insertRow(1); - let titleCell = row.insertCell(0); - let authorCell = row.insertCell(1); - let pagesCell = row.insertCell(2); - let wasReadCell = row.insertCell(3); - let deleteCell = row.insertCell(4); - titleCell.innerHTML = myLibrary[i].title; - authorCell.innerHTML = myLibrary[i].author; - pagesCell.innerHTML = myLibrary[i].pages; + const row = tableBody.insertRow(); + const titleCell = row.insertCell(0); + const authorCell = row.insertCell(1); + const pagesCell = row.insertCell(2); + const wasReadCell = row.insertCell(3); + const deleteCell = row.insertCell(4); + titleCell.textContent = myLibrary[i].title; + authorCell.textContent = myLibrary[i].author; + pagesCell.textContent = myLibrary[i].pages; //add and wait for action for read/unread button - let changeBut = document.createElement("button"); - changeBut.id = i; - changeBut.className = "btn btn-success"; - wasReadCell.appendChild(changeBut); - let readStatus = ""; - if (myLibrary[i].check == true) { - readStatus = "Yes"; - } else { - readStatus = "No"; - } - changeBut.innerText = readStatus; + const changeButton = document.createElement("button"); + changeButton.id = i; + changeButton.className = "btn btn-success"; + wasReadCell.appendChild(changeButton); + changeButton.innerText = myLibrary[i].check ? "Yes" : "No"; - changeBut.addEventListener("click", function () { + changeButton.addEventListener("click", function () { myLibrary[i].check = !myLibrary[i].check; render(); }); //add delete button to every row and render again - let delBut = document.createElement("button"); - delBut.id = i + 5; + const delBut = document.createElement("button"); deleteCell.appendChild(delBut); delBut.className = "btn btn-warning"; delBut.innerHTML = "Delete"; delBut.addEventListener("click", function () { - alert(`You've deleted title: ${myLibrary[i].title}`); + const deletedTitle = myLibrary[i].title; myLibrary.splice(i, 1); + alert(`You've deleted title: ${deletedTitle}`); render(); }); } } + +document.getElementById("add-book-btn").addEventListener("click", addBook); diff --git a/debugging/book-library/style.css b/debugging/book-library/style.css index 302950cb..0013d1be 100644 --- a/debugging/book-library/style.css +++ b/debugging/book-library/style.css @@ -16,4 +16,4 @@ button.btn-info { margin: 20px; -} +} \ No newline at end of file From f8030bf174208b250e386ac53acd12c3fa91524f Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Fri, 15 May 2026 04:03:38 +0100 Subject: [PATCH 6/6] changes made to index to pass validator --- debugging/book-library/index.html | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 3f2fe9c3..4abca1db 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -9,7 +9,7 @@ - + @@ -53,8 +53,6 @@

Library

- -