From d89b495c06e2665768748018ac43ee24998ef980 Mon Sep 17 00:00:00 2001 From: Shuheda Date: Sat, 11 Apr 2026 16:28:42 +0100 Subject: [PATCH 1/6] Creating PR --- debugging/book-library/index.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71..3286625a 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,7 +1,7 @@ - + - + Shuheda Library type="submit" value="Submit" class="btn btn-primary" - onclick="submit();" + onclick="submit()" /> From 81cebe8f774c5c26220f605029af10498c81b3de Mon Sep 17 00:00:00 2001 From: Shuheda Date: Sat, 18 Apr 2026 14:22:02 +0100 Subject: [PATCH 2/6] file index.html amended --- debugging/book-library/index.html | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 3286625a..2239f1dc 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,7 +1,7 @@ - Shuheda + My Book Library Library
Library /> Library value="" />Read - +
@@ -91,6 +88,6 @@

Library

- + From c9d358cf34be83b1b0f3a1b0fc17f001457fe4e4 Mon Sep 17 00:00:00 2001 From: Shuheda Date: Sat, 18 Apr 2026 14:44:26 +0100 Subject: [PATCH 3/6] script.js file amended --- debugging/book-library/script.js | 101 +++++++++++++++++-------------- 1 file changed, 54 insertions(+), 47 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d..af553746 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,45 +1,62 @@ let myLibrary = []; -window.addEventListener("load", function (e) { +const titleInputEl = document.getElementById("title"); +const authorInputEl = document.getElementById("author"); +const pagesInputEl = document.getElementById("pages"); +const isReadInputEl = document.getElementById("check"); +const submitBookBtnEl = document.getElementById("submit-book-btn"); +const displayTableEl = document.getElementById("display"); + +window.addEventListener("load", function () { populateStorage(); render(); }); function populateStorage() { - if (myLibrary.length == 0) { - let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true); + if (myLibrary.length === 0) { + let book1 = new Book("Robison Crusoe", "Daniel Defoe", 252, true); let book2 = new Book( "The Old Man and the Sea", "Ernest Hemingway", - "127", + 127, true ); myLibrary.push(book1); myLibrary.push(book2); - render(); } } -const title = document.getElementById("title"); -const author = document.getElementById("author"); -const pages = document.getElementById("pages"); -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 +//via Book function and start render function function submit() {function submit() { function submit() { + const normalizedTitle = titleInputEl.value.trim(); + const normalizedAuthor = authorInputEl.value.trim(); + const pagesCount = Number(pagesInputEl.value); + if ( - title.value == null || - title.value == "" || - pages.value == null || - pages.value == "" + normalizedTitle === "" || + normalizedAuthor === "" || + !Number.isInteger(pagesCount) || + pagesCount <= 0 ) { - alert("Please fill all fields!"); + alert( + "Please fill all fields correctly. Title and author are required, and page count must be a positive whole number." + ); return false; } else { - let book = new Book(title.value, title.value, pages.value, check.checked); - library.push(book); + let book = new Book( + normalizedTitle, + normalizedAuthor, + pagesCount, + isReadInputEl.checked + ); + myLibrary.push(book); render(); + + titleInputEl.value = ""; + authorInputEl.value = ""; + pagesInputEl.value = ""; + isReadInputEl.checked = false; } } @@ -51,53 +68,43 @@ function Book(title, author, pages, check) { } function render() { - let table = document.getElementById("display"); - let rowsNumber = table.rows.length; - //delete old table - for (let n = rowsNumber - 1; n > 0; n-- { - table.deleteRow(n); - } + const tableBodyEl = displayTableEl.tBodies[0]; + tableBodyEl.replaceChildren(); + //insert updated row and cells let length = myLibrary.length; for (let i = 0; i < length; i++) { - let row = table.insertRow(1); + let row = tableBodyEl.insertRow(); 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; + titleCell.textContent = myLibrary[i].title; + authorCell.textContent = myLibrary[i].author; + pagesCell.textContent = String(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 == false) { - readStatus = "Yes"; - } else { - readStatus = "No"; - } - changeBut.innerText = readStatus; + let toggleReadButton = document.createElement("button"); + toggleReadButton.className = "btn btn-success"; + wasReadCell.appendChild(toggleReadButton); + toggleReadButton.textContent = myLibrary[i].check === false ? "No" : "Yes"; - changeBut.addEventListener("click", function () { + toggleReadButton.addEventListener("click", function () { myLibrary[i].check = !myLibrary[i].check; 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 () { - alert(`You've deleted title: ${myLibrary[i].title}`); + let deleteButton = document.createElement("button"); + deleteCell.appendChild(deleteButton); + deleteButton.className = "btn btn-warning"; + deleteButton.textContent = "Delete"; + deleteButton.addEventListener("click", function () { + const deletedTitle = myLibrary[i].title; myLibrary.splice(i, 1); render(); + alert(`You've deleted title: ${deletedTitle}`); }); } } From 2bfc0a08371811f52528c7c73c0da9684a81b975 Mon Sep 17 00:00:00 2001 From: Shuheda Date: Sat, 18 Apr 2026 14:47:12 +0100 Subject: [PATCH 4/6] align amended on style.css --- debugging/book-library/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debugging/book-library/style.css b/debugging/book-library/style.css index 302950cb..2d40464b 100644 --- a/debugging/book-library/style.css +++ b/debugging/book-library/style.css @@ -1,7 +1,7 @@ .form-group { width: 400px; height: 300px; - align-self: left; + align-self: flex-start; padding-left: 20px; } From 922659e7abdafae79bba5c830cb61256807e857a Mon Sep 17 00:00:00 2001 From: Shuheda Date: Sun, 19 Apr 2026 23:11:13 +0100 Subject: [PATCH 5/6] errors in index.html fixed --- debugging/book-library/index.html | 42 ++++++++++++------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 2239f1dc..e4d652a3 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,12 +1,10 @@ - + My Book Library - + + + @@ -14,7 +12,7 @@ rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" /> - + @@ -37,6 +35,7 @@

Library

name="title" required /> + Library name="author" required /> + Library name="pages" required /> - - @@ -77,15 +75,7 @@

Library

- - - - - - - - - + From f35abf1a458fda07f9e60ac86d2b0f679a58c3bc Mon Sep 17 00:00:00 2001 From: Shuheda Date: Sun, 19 Apr 2026 23:20:39 +0100 Subject: [PATCH 6/6] Declared myLibrary using const instead of let --- debugging/book-library/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index af553746..be5d4805 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,4 +1,4 @@ -let myLibrary = []; +const myLibrary = []; const titleInputEl = document.getElementById("title"); const authorInputEl = document.getElementById("author"); @@ -88,7 +88,7 @@ function render() { let toggleReadButton = document.createElement("button"); toggleReadButton.className = "btn btn-success"; wasReadCell.appendChild(toggleReadButton); - toggleReadButton.textContent = myLibrary[i].check === false ? "No" : "Yes"; + toggleReadButton.textContent = myLibrary[i].check ? "Yes" : "No"; toggleReadButton.addEventListener("click", function () { myLibrary[i].check = !myLibrary[i].check;