From 9d43e785aa8e7677031cad46d5c818128e27729a Mon Sep 17 00:00:00 2001 From: mervereis Date: Sat, 18 Apr 2026 15:55:17 +0100 Subject: [PATCH 1/7] changes made for js in sprint-1 --- Sprint-1/destructuring/exercise-1/exercise.js | 2 +- Sprint-1/destructuring/exercise-2/exercise.js | 14 ++++++++++++++ Sprint-1/destructuring/exercise-3/exercise.js | 12 ++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 1ff2ac5c..2b7fd100 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -6,7 +6,7 @@ const personOne = { // Update the parameter to this function to make it work. // Don't change anything else. -function introduceYourself(___________________________) { +function introduceYourself({ name, favouriteFood, age }) { console.log( `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` ); diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb..53d5f2a1 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,17 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +for (const { firstName, lastName, house } of hogwarts) { + if (house === "Gryffindor") { + console.log(`${firstName} ${lastName}`); + } +} +console.log("Task1"); + +for (const { firstName, lastName, occupation, pet } of hogwarts) { + if (occupation === "Teacher" && pet) { + console.log(`${firstName} ${lastName}`); + } +} +console.log("task2"); diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e..ee87a14c 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,15 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; + +console.log(order[0]); + +function x(array) { + let b; + for (let i = 0; i < array.length; i++) { + b += i.itemName; + } + return b; +} + +console.log(x(order)); From 6564055892a8487d5a0d9b4d69a970918449be01 Mon Sep 17 00:00:00 2001 From: mervereis Date: Sat, 18 Apr 2026 20:51:11 +0100 Subject: [PATCH 2/7] fixed the bugs --- debugging/book-library/index.html | 146 ++++++++++++------------------ debugging/book-library/script.js | 84 +++++++++-------- 2 files changed, 101 insertions(+), 129 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71..2adbb784 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,96 +1,64 @@ - - - - - - - - - - + - -
-

Library

-

Add books to your virtual library

-
+ + My Virtual 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 75ce6c1d..6b3915bd 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,4 +1,4 @@ -let myLibrary = []; +const myLibrary = []; window.addEventListener("load", function (e) { populateStorage(); @@ -7,11 +7,11 @@ 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( + const book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true); + const book2 = new Book( "The Old Man and the Sea", "Ernest Hemingway", - "127", + 127, true ); myLibrary.push(book1); @@ -20,25 +20,34 @@ function populateStorage() { } } -const title = document.getElementById("title"); -const author = document.getElementById("author"); -const pages = document.getElementById("pages"); -const check = document.getElementById("check"); +const titleInput = document.getElementById("title"); +const authorInput = document.getElementById("author"); +const pagesInput = document.getElementById("pages"); +const readCheckBox = 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 == "" - ) { + const trimmedTitle = titleInput.value.trim(); + const trimmedAuthor = authorInput.value.trim(); + const trimmedPages = +pagesInput.value.trim(); + + if (!trimmedTitle || !trimmedAuthor || !trimmedPages) { alert("Please fill all fields!"); return false; } else { - let book = new Book(title.value, title.value, pages.value, check.checked); - library.push(book); + let book = new Book( + trimmedTitle, + trimmedAuthor, + trimmedPages, + readCheckbox.checked + ); + myLibrary.push(book); + + titleInput.value = ""; + authorInput.value = ""; + pagesInput.value = ""; + readCheckbox.checked = false; render(); } } @@ -51,37 +60,31 @@ function Book(title, author, pages, check) { } function render() { - let table = document.getElementById("display"); - let rowsNumber = table.rows.length; + const table = document.getElementById("display"); + const 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 - let length = myLibrary.length; + const 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; + const row = table.insertRow(1); + const titleCell = row.insertCell(0); + const authorCell = row.insertCell(1); + const pagesCell = row.insertCell(2); + const wasReadCell = row.insertCell(3); + const deleteCell = row.insertCell(4); + titleCell.textContent = myLibrary[i].title; + authorCell.textContent = myLibrary[i].author; + pagesCell.textContent = myLibrary[i].pages; //add and wait for action for read/unread button - let changeBut = document.createElement("button"); + const 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.innerHTML = myLibrary[i].check ? "Yes" : "No"; changeBut.addEventListener("click", function () { myLibrary[i].check = !myLibrary[i].check; @@ -89,15 +92,16 @@ function render() { }); //add delete button to every row and render again - let delButton = document.createElement("button"); + const 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}`); + delBut.addEventListener("click", function () { + const deletedBook = myLibrary[i]; myLibrary.splice(i, 1); render(); + alert(`You've deleted title: ${deletedBook.title}`); }); } } From cb1e4e8889ec268b5e01cfc64717b389eefe168d Mon Sep 17 00:00:00 2001 From: mervereis Date: Sat, 18 Apr 2026 21:10:19 +0100 Subject: [PATCH 3/7] fixed the bugs --- debugging/book-library/index.html | 2 +- debugging/book-library/script.js | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 2adbb784..62e0ef95 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -18,7 +18,7 @@

Library

Add books to your virtual library

- diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 6b3915bd..5940dc75 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -20,10 +20,12 @@ function populateStorage() { } } -const titleInput = document.getElementById("title"); -const authorInput = document.getElementById("author"); -const pagesInput = document.getElementById("pages"); -const readCheckBox = document.getElementById("check"); +function Book(title, author, pages, check) { + this.title = title; + this.author = author; + this.pages = pages; + this.check = 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 From 17bb589321d65a5c0e3386ca2d92218cbf0564dd Mon Sep 17 00:00:00 2001 From: mervereis Date: Wed, 22 Apr 2026 09:34:25 +0100 Subject: [PATCH 4/7] Fix input validation and data type for book pages in submit function --- debugging/book-library/script.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 5940dc75..365ce4dd 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -11,7 +11,7 @@ function populateStorage() { const book2 = new Book( "The Old Man and the Sea", "Ernest Hemingway", - 127, + "127", true ); myLibrary.push(book1); @@ -32,16 +32,16 @@ function Book(title, author, pages, check) { function submit() { const trimmedTitle = titleInput.value.trim(); const trimmedAuthor = authorInput.value.trim(); - const trimmedPages = +pagesInput.value.trim(); + const trimmedPageNumbers = +pagesInput.value.trim(); - if (!trimmedTitle || !trimmedAuthor || !trimmedPages) { - alert("Please fill all fields!"); + if (!trimmedTitle || !trimmedAuthor || !Number.isInteger(trimmedPageNumbers) || trimmedPageNumbers <= 0) { + alert("Please fill all fields! Page count must be a positive integer."); return false; } else { let book = new Book( trimmedTitle, trimmedAuthor, - trimmedPages, + trimmedPageNumbers, readCheckbox.checked ); myLibrary.push(book); @@ -63,11 +63,9 @@ function Book(title, author, pages, check) { function render() { const table = document.getElementById("display"); - const rowsNumber = table.rows.length; - //delete old table - for (let n = rowsNumber - 1; n > 0; n--) { - table.deleteRow(n); - } + const tbody = table.querySelector("tbody"); + //clear tbody + tbody.innerHTML = ""; //insert updated row and cells const length = myLibrary.length; for (let i = 0; i < length; i++) { @@ -83,7 +81,6 @@ function render() { //add and wait for action for read/unread button const changeBut = document.createElement("button"); - changeBut.id = i; changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); changeBut.innerHTML = myLibrary[i].check ? "Yes" : "No"; @@ -94,8 +91,7 @@ function render() { }); //add delete button to every row and render again - const delButton = document.createElement("button"); - delBut.id = i + 5; + const delBut = document.createElement("button"); deleteCell.appendChild(delBut); delBut.className = "btn btn-warning"; delBut.innerHTML = "Delete"; From 641609b1b75af21cb0f4aa7cf2a17ebd06df6135 Mon Sep 17 00:00:00 2001 From: mervereis <124799990+mervereis@users.noreply.github.com> Date: Wed, 22 Apr 2026 09:38:06 +0100 Subject: [PATCH 5/7] Fix parameter for introduceYourself function Updated the parameter of introduceYourself function to enable destructuring. --- Sprint-1/destructuring/exercise-1/exercise.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 2b7fd100..1ff2ac5c 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -6,7 +6,7 @@ const personOne = { // Update the parameter to this function to make it work. // Don't change anything else. -function introduceYourself({ name, favouriteFood, age }) { +function introduceYourself(___________________________) { console.log( `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` ); From 10430581b9501f3aa8cfc6fdb03f79095c35439b Mon Sep 17 00:00:00 2001 From: mervereis <124799990+mervereis@users.noreply.github.com> Date: Wed, 22 Apr 2026 09:38:47 +0100 Subject: [PATCH 6/7] Remove unused loops and console logs from exercise.js --- Sprint-1/destructuring/exercise-2/exercise.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index 53d5f2a1..e11b75eb 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,17 +70,3 @@ let hogwarts = [ occupation: "Teacher", }, ]; - -for (const { firstName, lastName, house } of hogwarts) { - if (house === "Gryffindor") { - console.log(`${firstName} ${lastName}`); - } -} -console.log("Task1"); - -for (const { firstName, lastName, occupation, pet } of hogwarts) { - if (occupation === "Teacher" && pet) { - console.log(`${firstName} ${lastName}`); - } -} -console.log("task2"); From 6afdec5b1bc1bc2e58d268e3ddd353149ebcd81b Mon Sep 17 00:00:00 2001 From: mervereis <124799990+mervereis@users.noreply.github.com> Date: Wed, 22 Apr 2026 09:39:22 +0100 Subject: [PATCH 7/7] Update exercise.js --- Sprint-1/destructuring/exercise-3/exercise.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index ee87a14c..b3a36f4e 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,15 +6,3 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; - -console.log(order[0]); - -function x(array) { - let b; - for (let i = 0; i < array.length; i++) { - b += i.itemName; - } - return b; -} - -console.log(x(order));