From 4cdcc40e5e64b34d7e76d58b19ab15d8bdf24b34 Mon Sep 17 00:00:00 2001 From: Elisabeth-Matulian Date: Fri, 20 Mar 2026 13:14:05 +0000 Subject: [PATCH 1/4] completed exercises object destructuring --- Sprint-1/destructuring/exercise-1/exercise.js | 2 +- Sprint-1/destructuring/exercise-2/exercise.js | 27 +++++++++++++++++++ Sprint-1/destructuring/exercise-3/exercise.js | 12 +++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 1ff2ac5c..7bd6c79b 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, age, favouriteFood} = personOne) { 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..80c776df 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,30 @@ let hogwarts = [ occupation: "Teacher", }, ]; + + + +function displayGryffindor(hogwarts) { + let list = []; + for (const obj of hogwarts) { + const {firstName, lastName, house} = obj; + if (house === "Gryffindor") { + list.push(`${firstName} ${lastName}`) + } + } + return list; +} +console.log(displayGryffindor(hogwarts)); + + +function displayPetsOwners(hogwarts) { + let list = []; + for (const obj of hogwarts) { + const {firstName, lastName, pet, occupation} = obj; + if (pet && occupation === "Teacher") { + list.push(`${firstName} ${lastName}`) + } + } + return list; +} +console.log(displayPetsOwners(hogwarts)); diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e..cd11824e 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 }, ]; + +function printOrder(order) { + let printOut = "QTY".padEnd(8, " ") + "ITEM".padEnd(20, " ") + "TOTAL\n"; + let total = 0; + for (const { itemName, quantity, unitPricePence } of order) { + printOut += `${String(quantity).padEnd(8, " ")}${itemName.padEnd(20, " ")}${((quantity * unitPricePence) / 100).toFixed(2)}\n`; + total += unitPricePence * quantity; + } + printOut += `Total: ${(total / 100).toFixed(2)}`; + return printOut; +} +console.log(printOrder(order)); From 81e1e8b2e45163c0971794b914c244f66ed6c86c Mon Sep 17 00:00:00 2001 From: Elisabeth-Matulian Date: Tue, 31 Mar 2026 15:09:35 +0100 Subject: [PATCH 2/4] fix: add missing bracket in for-loop --- debugging/book-library/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d..eed706fd 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -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 9057a462d90b3e3ef3d8e40cd28211e08c140f5a Mon Sep 17 00:00:00 2001 From: Elisabeth-Matulian Date: Wed, 1 Apr 2026 19:50:26 +0100 Subject: [PATCH 3/4] fix: correct variable names, author field, event typo, read status value --- 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 eed706fd..7703af0f 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -37,8 +37,8 @@ function submit() { 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(title.value, author.value, pages.value, check.checked); + myLibrary.push(book); render(); } } @@ -76,10 +76,10 @@ function render() { changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); let readStatus = ""; - if (myLibrary[i].check == false) { - readStatus = "Yes"; - } else { + if (myLibrary[i].check === false) { readStatus = "No"; + } else { + readStatus = "Yes"; } changeBut.innerText = readStatus; @@ -89,12 +89,12 @@ 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"; delBut.innerHTML = "Delete"; - delBut.addEventListener("clicks", function () { + delBut.addEventListener("click", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); From 33fc34f1259fb2d07567310d97e2417fd0b80b78 Mon Sep 17 00:00:00 2001 From: Elisabeth-Matulian Date: Wed, 1 Apr 2026 19:56:53 +0100 Subject: [PATCH 4/4] fix: add page title to HTML head --- debugging/book-library/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71..fef4f0d7 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,7 +1,7 @@ - + My Book Library