From c569a2d3c1d290138484f96949aca17dfe82d6d0 Mon Sep 17 00:00:00 2001 From: MaharitB Date: Fri, 27 Nov 2026 21:26:38 +0000 Subject: [PATCH 1/4] website loads nowa and delet button appears --- debugging/book-library/script.js | 39 ++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d3..87ffcee0a 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -7,13 +7,18 @@ 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( - "The Old Man and the Sea", - "Ernest Hemingway", - "127", - true - ); + let book1 = new Book({ + title: "Robison Crusoe", + author: "Daniel Defoe", + pages: "252", + check: true, + }); + let book2 = new Book({ + title: "The Old Man and the Sea", + author: "Ernest Hemingway", + pages: "127", + check: true, + }); myLibrary.push(book1); myLibrary.push(book2); render(); @@ -30,20 +35,20 @@ const check = document.getElementById("check"); function submit() { if ( title.value == null || - title.value == "" || + author.value == "" || pages.value == null || - pages.value == "" + check.value == "" ) { alert("Please fill all fields!"); return false; } else { let book = new Book(title.value, title.value, pages.value, check.checked); - library.push(book); + myLibrary.push(book); render(); } } -function Book(title, author, pages, check) { +function Book({ title, author, pages, check }) { this.title = title; this.author = author; this.pages = pages; @@ -54,7 +59,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 @@ -90,11 +95,11 @@ 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; + 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(); From f5cc067b10f2bc58448706ae2ef301250422be39 Mon Sep 17 00:00:00 2001 From: MaharitB Date: Fri, 27 Nov 2026 21:31:45 +0000 Subject: [PATCH 2/4] now if the book is read will show yes on the page --- 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 87ffcee0a..9fcebc45b 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -82,9 +82,9 @@ function render() { wasReadCell.appendChild(changeBut); let readStatus = ""; if (myLibrary[i].check == false) { - readStatus = "Yes"; - } else { readStatus = "No"; + } else { + readStatus = "Yes"; } changeBut.innerText = readStatus; From f4ca69c82908e91009b1bed31613fb83efcee3db Mon Sep 17 00:00:00 2001 From: MaharitB Date: Fri, 27 Nov 2026 22:58:40 +0000 Subject: [PATCH 3/4] it can add a book when pressed submit --- debugging/book-library/script.js | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 9fcebc45b..06cae2b8f 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -7,18 +7,13 @@ window.addEventListener("load", function (e) { function populateStorage() { if (myLibrary.length == 0) { - let book1 = new Book({ - title: "Robison Crusoe", - author: "Daniel Defoe", - pages: "252", - check: true, - }); - let book2 = new Book({ - title: "The Old Man and the Sea", - author: "Ernest Hemingway", - pages: "127", - check: true, - }); + let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true); + let book2 = new Book( + "The Old Man and the Sea", + "Ernest Hemingway", + "127", + true + ); myLibrary.push(book1); myLibrary.push(book2); render(); @@ -34,21 +29,22 @@ const check = document.getElementById("check"); //via Book function and start render function function submit() { if ( - title.value == null || - author.value == "" || - pages.value == null || - check.value == "" + title.value === "" || + author.value === "" || + pages.value === null || + check.value === "false" ) { 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); + console.log(title.value); myLibrary.push(book); render(); } } -function Book({ title, author, pages, check }) { +function Book(title, author, pages, check) { this.title = title; this.author = author; this.pages = pages; From cec2e90f90ec56b285de582a10ce84b9575ddc57 Mon Sep 17 00:00:00 2001 From: MaharitB Date: Sat, 28 Nov 2026 01:04:12 +0000 Subject: [PATCH 4/4] shows an alert when one of the input missing --- debugging/book-library/script.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 06cae2b8f..18b4de62f 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -29,10 +29,10 @@ const check = document.getElementById("check"); //via Book function and start render function function submit() { if ( - title.value === "" || - author.value === "" || - pages.value === null || - check.value === "false" + title.value == "" || + author.value == "" || + pages.value == "" || + check.value == "false" ) { alert("Please fill all fields!"); return false;