From d7e7b4c954ca733135bda1a2bccde2af14f645de Mon Sep 17 00:00:00 2001 From: marthak1 Date: Wed, 15 Apr 2026 17:47:07 +0100 Subject: [PATCH 01/11] fix error in render function for loo closing missing closing bracket --- 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 75ce6c1d..222d0b76 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,5 +1,5 @@ let myLibrary = []; - +it window.addEventListener("load", function (e) { populateStorage(); 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 From 11e500e7c6063c51b7ec3bfdec3880e682efff97 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Wed, 15 Apr 2026 19:15:19 +0100 Subject: [PATCH 02/11] update delete button --- debugging/book-library/script.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 222d0b76..21e79ebf 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,5 +1,4 @@ let myLibrary = []; -it window.addEventListener("load", function (e) { populateStorage(); render(); @@ -38,7 +37,7 @@ function submit() { return false; } else { let book = new Book(title.value, title.value, pages.value, check.checked); - library.push(book); + myLibrary.push(book); render(); } } @@ -89,7 +88,7 @@ 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"; @@ -101,3 +100,18 @@ function render() { }); } } +// My website should be able to: + +// - View a list of books that I've read +// - Add books to a list of books that I've read +// - Including title, author, number of pages and if I've read it +// - If any of the information is missing it shouldn't add the book and should show an alert +// - Remove books from my list + +// ## Bugs to be fixed + +// 1. Website loads but doesn't show any books +// 2. Error in console when you try to add a book +// 3. It uses the title name as the author name +// 4. Delete button is broken +// 5. When I add a book that I say I've read - it saves the wrong answer \ No newline at end of file From de9d89d280d60bb2fd874de45fb9e66cff2f9ff0 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Wed, 15 Apr 2026 20:55:46 +0100 Subject: [PATCH 03/11] update add book function and inputs --- debugging/book-library/index.html | 2 +- debugging/book-library/script.js | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71..e24a68f3 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -65,7 +65,7 @@

Library

type="submit" value="Submit" class="btn btn-primary" - onclick="submit();" + id ="submit-btn" /> diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 21e79ebf..2c35bb52 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -15,7 +15,6 @@ function populateStorage() { ); myLibrary.push(book1); myLibrary.push(book2); - render(); } } @@ -23,6 +22,12 @@ const title = document.getElementById("title"); const author = document.getElementById("author"); const pages = document.getElementById("pages"); const check = document.getElementById("check"); +const submitBtn = document.getElementById("submit-btn"); + +submitBtn.addEventListener("click", function (event) { + event.preventDefault(); + submit(); +}); //check the right input from forms and if its ok -> add the new book (object in array) //via Book function and start render function @@ -36,7 +41,7 @@ function submit() { alert("Please fill all fields!"); return false; } else { - let book = new Book(title.value, title.value, pages.value, check.checked); + let book = new Book(title.value, author.value, pages.value, check.checked); myLibrary.push(book); render(); } @@ -55,7 +60,7 @@ function render() { //delete old table for (let n = rowsNumber - 1; n > 0; n--){ table.deleteRow(n); - } + } //insert updated row and cells let length = myLibrary.length; for (let i = 0; i < length; i++) { @@ -110,7 +115,7 @@ function render() { // ## Bugs to be fixed -// 1. Website loads but doesn't show any books +// 1. Website loads but doesn't show any books => fixed // 2. Error in console when you try to add a book // 3. It uses the title name as the author name // 4. Delete button is broken From 3dadc55f78fa39a9b252720f0bb2844aa4c32133 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Wed, 15 Apr 2026 21:35:49 +0100 Subject: [PATCH 04/11] fixed delete button --- debugging/book-library/script.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 2c35bb52..31ec0fd4 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -81,9 +81,9 @@ function render() { wasReadCell.appendChild(changeBut); let readStatus = ""; if (myLibrary[i].check == false) { - readStatus = "Yes"; - } else { readStatus = "No"; + } else { + readStatus = "Yes"; } changeBut.innerText = readStatus; @@ -98,7 +98,7 @@ function render() { 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(); @@ -116,7 +116,7 @@ function render() { // ## Bugs to be fixed // 1. Website loads but doesn't show any books => fixed -// 2. Error in console when you try to add a book -// 3. It uses the title name as the author name -// 4. Delete button is broken -// 5. When I add a book that I say I've read - it saves the wrong answer \ No newline at end of file +// 2. Error in console when you try to add a book => fixed +// 3. It uses the title name as the author name => fixed +// 4. Delete button is broken =>git +// 5. When I add a book that I say I've read - it saves the wrong answer => \ No newline at end of file From 9fb77a91e8f2ff8478f497b30d537693bdc99d04 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Wed, 15 Apr 2026 21:37:23 +0100 Subject: [PATCH 05/11] removed unused comment --- debugging/book-library/script.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 31ec0fd4..9537130d 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -105,18 +105,3 @@ function render() { }); } } -// My website should be able to: - -// - View a list of books that I've read -// - Add books to a list of books that I've read -// - Including title, author, number of pages and if I've read it -// - If any of the information is missing it shouldn't add the book and should show an alert -// - Remove books from my list - -// ## Bugs to be fixed - -// 1. Website loads but doesn't show any books => fixed -// 2. Error in console when you try to add a book => fixed -// 3. It uses the title name as the author name => fixed -// 4. Delete button is broken =>git -// 5. When I add a book that I say I've read - it saves the wrong answer => \ No newline at end of file From da350c1b05e012bd77dcc1db519b2fb3838225ea Mon Sep 17 00:00:00 2001 From: marthak1 Date: Wed, 15 Apr 2026 22:06:37 +0100 Subject: [PATCH 06/11] unco changes in html --- debugging/book-library/script.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 9537130d..a8b24945 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -105,3 +105,21 @@ function render() { }); } } +<<<<<<< HEAD +======= +// My website should be able to: + +// - View a list of books that I've read +// - Add books to a list of books that I've read +// - Including title, author, number of pages and if I've read it +// - If any of the information is missing it shouldn't add the book and should show an alert +// - Remove books from my list + +// ## Bugs to be fixed + +// 1. Website loads but doesn't show any books => fixed +// 2. Error in console when you try to add a book => fixed +// 3. It uses the title name as the author name => fixed +// 4. Delete button is broken =>git +// 5. When I add a book that I say I've read - it saves the wrong answer => +>>>>>>> c637046 (unco changes in html) From 2132c95b8f03a4960604cb1e437d4973ec040b62 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Wed, 15 Apr 2026 22:56:11 +0100 Subject: [PATCH 07/11] removed unused comment --- debugging/book-library/script.js | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index a8b24945..c7da752c 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -105,21 +105,4 @@ function render() { }); } } -<<<<<<< HEAD -======= -// My website should be able to: -// - View a list of books that I've read -// - Add books to a list of books that I've read -// - Including title, author, number of pages and if I've read it -// - If any of the information is missing it shouldn't add the book and should show an alert -// - Remove books from my list - -// ## Bugs to be fixed - -// 1. Website loads but doesn't show any books => fixed -// 2. Error in console when you try to add a book => fixed -// 3. It uses the title name as the author name => fixed -// 4. Delete button is broken =>git -// 5. When I add a book that I say I've read - it saves the wrong answer => ->>>>>>> c637046 (unco changes in html) From 856dff76bc4f427dfd0f1018ab68297a963a542f Mon Sep 17 00:00:00 2001 From: marthak1 Date: Fri, 17 Apr 2026 18:37:19 +0100 Subject: [PATCH 08/11] validate html code --- debugging/book-library/index.html | 146 ++++++++++++------------------ debugging/book-library/script.js | 1 + 2 files changed, 58 insertions(+), 89 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index e24a68f3..87bd1542 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,96 +1,64 @@ - - - - - - - - - - + - -
-

Library

-

Add books to your virtual library

-
+ + + + Book 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 c7da752c..6e577ada 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -106,3 +106,4 @@ function render() { } } + From 341fdedcb356156e0750af3b4b8a3dad4aaa6bad Mon Sep 17 00:00:00 2001 From: marthak1 Date: Fri, 17 Apr 2026 18:52:28 +0100 Subject: [PATCH 09/11] refactor page count with number type and update element variable names --- debugging/book-library/index.html | 2 +- debugging/book-library/script.js | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 87bd1542..55d58a46 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -58,7 +58,7 @@

Library

- + \ No newline at end of file diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 6e577ada..fd25116d 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -6,11 +6,11 @@ window.addEventListener("load", function (e) { function populateStorage() { if (myLibrary.length == 0) { - let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true); + 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); @@ -18,13 +18,13 @@ function populateStorage() { } } -const title = document.getElementById("title"); -const author = document.getElementById("author"); -const pages = document.getElementById("pages"); -const check = document.getElementById("check"); -const submitBtn = document.getElementById("submit-btn"); +const titleEl = document.getElementById("title"); +const authorEl = document.getElementById("author"); +const pagesEl = document.getElementById("pages"); +const checkEl = document.getElementById("check"); +const submitBtnEl = document.getElementById("submit-btn"); -submitBtn.addEventListener("click", function (event) { +submitBtnEl.addEventListener("click", function (event) { event.preventDefault(); submit(); }); @@ -33,15 +33,15 @@ submitBtn.addEventListener("click", function (event) { //via Book function and start render function function submit() { if ( - title.value == null || - title.value == "" || - pages.value == null || - pages.value == "" + titleEl.value == null || + titleEl.value == "" || + pagesEl.value == null || + pagesEl.value == "" ) { alert("Please fill all fields!"); return false; } else { - let book = new Book(title.value, author.value, pages.value, check.checked); + let book = new Book(titleEl.value, authorEl.value, pagesEl.value, checkEl.checked); myLibrary.push(book); render(); } From 2a37c415da83690cbb26d9e21defd144282acb1a Mon Sep 17 00:00:00 2001 From: marthak1 Date: Sat, 18 Apr 2026 12:01:38 +0100 Subject: [PATCH 10/11] refactor submit function by using logical NOT to validate input --- debugging/book-library/index.html | 3 ++- debugging/book-library/script.js | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 55d58a46..5f381d06 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -61,4 +61,5 @@

Library

- \ No newline at end of file + + diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index fd25116d..0f77880d 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -33,10 +33,9 @@ submitBtnEl.addEventListener("click", function (event) { //via Book function and start render function function submit() { if ( - titleEl.value == null || - titleEl.value == "" || - pagesEl.value == null || - pagesEl.value == "" + !titleEl.value || + !authorEl.value || + !pagesEl.value ) { alert("Please fill all fields!"); return false; From 3ba292d023c019c82367e94e8d5f9c032c8acd4a Mon Sep 17 00:00:00 2001 From: marthak1 Date: Sat, 18 Apr 2026 12:57:56 +0100 Subject: [PATCH 11/11] add html input validation --- .vscode/settings.json | 3 +++ debugging/book-library/index.html | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..30de70fe --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.acceptSuggestionOnEnter": "on" +} \ No newline at end of file diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 5f381d06..e554b011 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -25,16 +25,16 @@

Library

- + - + - + -
+