From d12dca275fec9007e5c074967d90702ab0471741 Mon Sep 17 00:00:00 2001 From: Kirill Kovzel Date: Tue, 16 Jul 2024 15:47:35 +0100 Subject: [PATCH 1/2] Add recommended VS Code extensions --- .vscode/extensions.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .vscode/extensions.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..2554907 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + "recommendations": [ + "esbenp.prettier-vscode", + "dbaeumer.vscode-eslint", + "streetsidesoftware.code-spell-checker", + "eamodio.gitlens", + "ritwickdey.LiveServer", + "vsliveshare.vsliveshare" + ] +} From 6d00158a66f670a8fe24dbd48d0637286125de86 Mon Sep 17 00:00:00 2001 From: Syed Arslan Date: Tue, 14 Jan 2025 13:52:34 +0100 Subject: [PATCH 2/2] fix code bugs --- book-library/script.js | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/book-library/script.js b/book-library/script.js index dc14a77..bc25179 100644 --- a/book-library/script.js +++ b/book-library/script.js @@ -1,6 +1,6 @@ let myLibrary = []; -window.addEventListener("load", function (e) { +window.addEventListener("load", function () { populateStorage(); render(); }); @@ -8,12 +8,7 @@ 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 book2 = new Book( "The Old Man and the Sea", "Ernest Hemingway", "127", true); myLibrary.push(book1); myLibrary.push(book2); render(); @@ -29,32 +24,30 @@ const check = document.getElementById("check"); //via Book function and start render function function submit() { if ( - title.value == null || title.value == "" || - pages.value == null || - pages.value == "" + author.value == "" || + pages.value == "" || + pages.value == null ) { 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) { this.title = title; this.author = author; this.pages = pages; this.check = check; } - 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 @@ -72,17 +65,11 @@ function render() { //add and wait for action for read/unread button let changeBut = document.createElement("button"); - changeBut.id = i; + changeBut.id = "read" + i; changeBut.className = "btn btn-success"; cell4.appendChild(changeBut); - let readStatus = ""; - if (myLibrary[i].check == false) { - readStatus = "Yes"; - } else { - readStatus = "No"; - } + let readStatus = myLibrary[i].check ? "Yes" : "No"; // Fixed read status logic changeBut.innerHTML = readStatus; - changeBut.addEventListener("click", function () { myLibrary[i].check = !myLibrary[i].check; render(); @@ -90,11 +77,11 @@ function render() { //add delete button to every row and render again let delButton = document.createElement("button"); - delBut.id = i + 5; - cell5.appendChild(delBut); - delBut.className = "btn btn-warning"; - delBut.innerHTML = "Delete"; - delBut.addEventListener("clicks", function () { + delButton.id = "del" + i; + cell5.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();