From 97c6d21382504027e2dfa5899f261a801c29f54b Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Thu, 20 Aug 2026 10:30:32 +0100 Subject: [PATCH 01/10] book lilbrary fix bug --- debugging/book-library/script.js | 121 +++++++++++++++++-------------- 1 file changed, 67 insertions(+), 54 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d3..5c4acccf5 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,22 +1,18 @@ let myLibrary = []; -window.addEventListener("load", function (e) { +window.addEventListener("load", function () { populateStorage(); render(); }); 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 + // Initialize sample data with two books + myLibrary.push(new Book("Robinson Crusoe", "Daniel Defoe", "252", true)); + + myLibrary.push( + new Book("The Old Man and the Sea", "Ernest Hemingway", "127", true) ); - myLibrary.push(book1); - myLibrary.push(book2); - render(); } } @@ -25,22 +21,42 @@ 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 function submit() { - if ( - title.value == null || - title.value == "" || - pages.value == null || - pages.value == "" - ) { + // remove empty spaces before and after author and title input + title.value = title.value.trim(); + author.value = author.value.trim(); + + // Check for empty input fields + if (!title.value || !author.value || !pages.value) { alert("Please fill all fields!"); - return false; - } else { - let book = new Book(title.value, title.value, pages.value, check.checked); - library.push(book); - render(); + return; + } + + // check if page number is a valid integer > 0 + if (isNaN(pages) || pages <= 0 || !Number.isInteger(pages)) { + alert("number of pages need to be a valid integer >0!"); + return; } + + // Create a new book object with input data + const newBook = new Book( + title.value, + author.value, + pages.value, + check.checked + ); + + // Add the new book to the library + myLibrary.push(newBook); + + // Update the display + render(); + + // Clear the form + title.value = ""; + author.value = ""; + pages.value = ""; + check.checked = false; } function Book(title, author, pages, check) { @@ -53,51 +69,48 @@ 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-- { + + // Remove existing rows except header + 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++) { - 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; - - //add and wait for action for read/unread button + + for (let i = 0; i < myLibrary.length; i++) { + let row = table.insertRow(); + + // Insert cells + row.insertCell().innerText = myLibrary[i].title; + row.insertCell().innerText = myLibrary[i].author; + row.insertCell().innerText = myLibrary[i].pages; + + // Read/Unread button + let readCell = row.insertCell(); + 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; + changeBut.innerText = myLibrary[i].check ? "Yes" : "No"; changeBut.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); + readCell.appendChild(changeBut); + + // Delete button + let deleteCell = row.insertCell(); + + let delBut = document.createElement("button"); delBut.className = "btn btn-warning"; - delBut.innerHTML = "Delete"; - delBut.addEventListener("clicks", function () { + delBut.innerText = "Delete"; + + delBut.addEventListener("click", function () { alert(`You've deleted title: ${myLibrary[i].title}`); + myLibrary.splice(i, 1); render(); }); + + deleteCell.appendChild(delBut); } } From 99acb04d6cc1908825ee5bb1430be0914003665f Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Thu, 20 Aug 2026 11:32:52 +0100 Subject: [PATCH 02/10] replace original files --- debugging/book-library/index (1).html | 96 +++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 debugging/book-library/index (1).html diff --git a/debugging/book-library/index (1).html b/debugging/book-library/index (1).html new file mode 100644 index 000000000..23acfa71e --- /dev/null +++ b/debugging/book-library/index (1).html @@ -0,0 +1,96 @@ + + + + + + + + + + + + + +
+

Library

+

Add books to your virtual library

+
+ + + +
+
+ + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + +
TitleAuthorNumber of PagesRead
+ + + + From cb00cff3fc8012bd954f0eec383cc25c0d9e1942 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Sat, 12 Sep 2026 14:50:49 +0100 Subject: [PATCH 03/10] html file --- fetch/programmer-humour/index.html | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 fetch/programmer-humour/index.html diff --git a/fetch/programmer-humour/index.html b/fetch/programmer-humour/index.html new file mode 100644 index 000000000..67db58fa1 --- /dev/null +++ b/fetch/programmer-humour/index.html @@ -0,0 +1,22 @@ +```html + + + + + + XKCD Comic + + + + + +

Latest XKCD Comic

+ +
+

Loading comic...

+
+ + + + +``` From 0253191f0a508bf559e4c72de2b75572a0e900fb Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Sat, 12 Sep 2026 14:51:25 +0100 Subject: [PATCH 04/10] css file update --- fetch/programmer-humour/script.js | 44 +++++++++++++++++++++++++++++++ fetch/programmer-humour/stle.css | 16 +++++++++++ 2 files changed, 60 insertions(+) create mode 100644 fetch/programmer-humour/script.js create mode 100644 fetch/programmer-humour/stle.css diff --git a/fetch/programmer-humour/script.js b/fetch/programmer-humour/script.js new file mode 100644 index 000000000..c96d8c11b --- /dev/null +++ b/fetch/programmer-humour/script.js @@ -0,0 +1,44 @@ +```js +function getLatestComic() { + fetch("https://xkcd.now.sh/?comic=latest") + .then((response) => { + if (!response.ok) { + throw new Error("Failed to fetch comic"); + } + + return response.json(); + }) + .then((data) => { + // Log the received JSON data + console.log(data); + + // Get the container + const comicContainer = document.getElementById("comic-container"); + + // Create an img element + const comicImage = document.createElement("img"); + + // Use the img property from the API + comicImage.src = data.img; + + // Add alt text + comicImage.alt = data.title; + + // Remove loading message + comicContainer.innerHTML = ""; + + // Add the image to the page + comicContainer.appendChild(comicImage); + }) + .catch((error) => { + console.error("Error:", error); + + const comicContainer = document.getElementById("comic-container"); + + comicContainer.innerHTML = "

Sorry, we couldn't load the comic.

"; + }); +} + +// Make the API call +getLatestComic(); +```; diff --git a/fetch/programmer-humour/stle.css b/fetch/programmer-humour/stle.css new file mode 100644 index 000000000..c827fbfa0 --- /dev/null +++ b/fetch/programmer-humour/stle.css @@ -0,0 +1,16 @@ +```css +body { + font-family: Arial, sans-serif; + text-align: center; + margin: 40px; +} + +#comic-container { + margin-top: 20px; +} + +img { + max-width: 100%; + height: auto; +} +``` From 11ed43b80b22313fd7baa2995dc566fdd043b7de Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Sat, 12 Sep 2026 14:54:15 +0100 Subject: [PATCH 05/10] adding script.js --- fetch/programmer-humour/script.js | 1 + 1 file changed, 1 insertion(+) diff --git a/fetch/programmer-humour/script.js b/fetch/programmer-humour/script.js index c96d8c11b..724444c54 100644 --- a/fetch/programmer-humour/script.js +++ b/fetch/programmer-humour/script.js @@ -42,3 +42,4 @@ function getLatestComic() { // Make the API call getLatestComic(); ```; +// From 92ea3530ab29b5ec65c14fb75a208e072559ac40 Mon Sep 17 00:00:00 2001 From: mandipsanger Date: Sat, 12 Sep 2026 15:05:04 +0100 Subject: [PATCH 06/10] Delete debugging/book-library/script.js --- debugging/book-library/script.js | 116 ------------------------------- 1 file changed, 116 deletions(-) delete mode 100644 debugging/book-library/script.js diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js deleted file mode 100644 index 5c4acccf5..000000000 --- a/debugging/book-library/script.js +++ /dev/null @@ -1,116 +0,0 @@ -let myLibrary = []; - -window.addEventListener("load", function () { - populateStorage(); - render(); -}); - -function populateStorage() { - if (myLibrary.length == 0) { - // Initialize sample data with two books - myLibrary.push(new Book("Robinson Crusoe", "Daniel Defoe", "252", true)); - - myLibrary.push( - new Book("The Old Man and the Sea", "Ernest Hemingway", "127", true) - ); - } -} - -const title = document.getElementById("title"); -const author = document.getElementById("author"); -const pages = document.getElementById("pages"); -const check = document.getElementById("check"); - -function submit() { - // remove empty spaces before and after author and title input - title.value = title.value.trim(); - author.value = author.value.trim(); - - // Check for empty input fields - if (!title.value || !author.value || !pages.value) { - alert("Please fill all fields!"); - return; - } - - // check if page number is a valid integer > 0 - if (isNaN(pages) || pages <= 0 || !Number.isInteger(pages)) { - alert("number of pages need to be a valid integer >0!"); - return; - } - - // Create a new book object with input data - const newBook = new Book( - title.value, - author.value, - pages.value, - check.checked - ); - - // Add the new book to the library - myLibrary.push(newBook); - - // Update the display - render(); - - // Clear the form - title.value = ""; - author.value = ""; - pages.value = ""; - check.checked = false; -} - -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; - - // Remove existing rows except header - for (let n = rowsNumber - 1; n > 0; n--) { - table.deleteRow(n); - } - - for (let i = 0; i < myLibrary.length; i++) { - let row = table.insertRow(); - - // Insert cells - row.insertCell().innerText = myLibrary[i].title; - row.insertCell().innerText = myLibrary[i].author; - row.insertCell().innerText = myLibrary[i].pages; - - // Read/Unread button - let readCell = row.insertCell(); - - let changeBut = document.createElement("button"); - changeBut.className = "btn btn-success"; - changeBut.innerText = myLibrary[i].check ? "Yes" : "No"; - - changeBut.addEventListener("click", function () { - myLibrary[i].check = !myLibrary[i].check; - render(); - }); - - readCell.appendChild(changeBut); - - // Delete button - let deleteCell = row.insertCell(); - - let delBut = document.createElement("button"); - delBut.className = "btn btn-warning"; - delBut.innerText = "Delete"; - - delBut.addEventListener("click", function () { - alert(`You've deleted title: ${myLibrary[i].title}`); - - myLibrary.splice(i, 1); - render(); - }); - - deleteCell.appendChild(delBut); - } -} From eb0bc135494b5a3288696e7bc0e8c02c89059d44 Mon Sep 17 00:00:00 2001 From: mandipsanger Date: Sat, 12 Sep 2026 15:07:17 +0100 Subject: [PATCH 07/10] Delete debugging/book-library/index (1).html --- debugging/book-library/index (1).html | 96 --------------------------- 1 file changed, 96 deletions(-) delete mode 100644 debugging/book-library/index (1).html diff --git a/debugging/book-library/index (1).html b/debugging/book-library/index (1).html deleted file mode 100644 index 23acfa71e..000000000 --- a/debugging/book-library/index (1).html +++ /dev/null @@ -1,96 +0,0 @@ - - - - - - - - - - - - - -
-

Library

-

Add books to your virtual library

-
- - - -
-
- - - - - - - - -
-
- - - - - - - - - - - - - - - - - - - - -
TitleAuthorNumber of PagesRead
- - - - From 4ca955aa2f3d485cd597196e69f2b5ff5270c00c Mon Sep 17 00:00:00 2001 From: mandipsanger Date: Sat, 12 Sep 2026 15:08:54 +0100 Subject: [PATCH 08/10] Delete fetch/programmer-humour/index.html --- fetch/programmer-humour/index.html | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 fetch/programmer-humour/index.html diff --git a/fetch/programmer-humour/index.html b/fetch/programmer-humour/index.html deleted file mode 100644 index 67db58fa1..000000000 --- a/fetch/programmer-humour/index.html +++ /dev/null @@ -1,22 +0,0 @@ -```html - - - - - - XKCD Comic - - - - - -

Latest XKCD Comic

- -
-

Loading comic...

-
- - - - -``` From 125792949bd80879236ce632d0a90e0fe16eca02 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Sat, 12 Sep 2026 16:11:49 +0100 Subject: [PATCH 09/10] adding script.js --- debugging/book-library/script .js | 103 ++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 debugging/book-library/script .js diff --git a/debugging/book-library/script .js b/debugging/book-library/script .js new file mode 100644 index 000000000..75ce6c1d3 --- /dev/null +++ b/debugging/book-library/script .js @@ -0,0 +1,103 @@ +let myLibrary = []; + +window.addEventListener("load", function (e) { + populateStorage(); + render(); +}); + +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 + ); + 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 +function submit() { + if ( + title.value == null || + title.value == "" || + pages.value == null || + pages.value == "" + ) { + alert("Please fill all fields!"); + return false; + } else { + let book = new Book(title.value, title.value, pages.value, check.checked); + library.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-- { + table.deleteRow(n); + } + //insert updated row and cells + 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; + + //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; + + changeBut.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}`); + myLibrary.splice(i, 1); + render(); + }); + } +} From 29343f6368de6ce91c8b679ad7c9ec8bc819b216 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Sat, 12 Sep 2026 16:18:28 +0100 Subject: [PATCH 10/10] adding script.js original --- debugging/book-library/script.js | 103 +++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 debugging/book-library/script.js diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js new file mode 100644 index 000000000..75ce6c1d3 --- /dev/null +++ b/debugging/book-library/script.js @@ -0,0 +1,103 @@ +let myLibrary = []; + +window.addEventListener("load", function (e) { + populateStorage(); + render(); +}); + +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 + ); + 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 +function submit() { + if ( + title.value == null || + title.value == "" || + pages.value == null || + pages.value == "" + ) { + alert("Please fill all fields!"); + return false; + } else { + let book = new Book(title.value, title.value, pages.value, check.checked); + library.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-- { + table.deleteRow(n); + } + //insert updated row and cells + 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; + + //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; + + changeBut.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}`); + myLibrary.splice(i, 1); + render(); + }); + } +}