From 1cddaaabb8d5d8265945ba6816125d91fbf7c7ee Mon Sep 17 00:00:00 2001 From: dona-shehu Date: Wed, 29 Jul 2026 23:07:34 +0100 Subject: [PATCH 1/9] Introduce yourself destructuring object --- Sprint-1/destructuring/exercise-1/exercise.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 1ff2ac5c..f4e48506 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -1,14 +1,15 @@ const personOne = { - name: "Popeye", + firstName: "Popeye", age: 34, favouriteFood: "Spinach", }; - + +let {firstName, age, favouriteFood} = personOne // Update the parameter to this function to make it work. // Don't change anything else. -function introduceYourself(___________________________) { +function introduceYourself() { console.log( - `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` + `Hello, my name is ${firstName}. I am ${age} years old and my favourite food is ${favouriteFood}.` ); } From c92876ee0a3b7f5b121e1ba7244b204efedde7c9 Mon Sep 17 00:00:00 2001 From: dona-shehu Date: Wed, 29 Jul 2026 23:09:20 +0100 Subject: [PATCH 2/9] gryffindor and teacherWithPet, destructuring array of objects --- Sprint-1/destructuring/exercise-2/exercise.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb..2852173f 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,27 @@ let hogwarts = [ occupation: "Teacher", }, ]; +function gryffindorforStudent(){ + let allStudents = ""; + for(let student of hogwarts){ + let {firstName,lastName,house,pet,occupation} = student; + if (house === "Gryffindor"){ + allStudents += `${firstName} ${lastName}\n` + } + } + return allStudents; +} + +function teacherWithPet(){ + let allTeachers = ""; + for(const person of hogwarts){ + let {firstName, lastName,pet, occupation} = person; + if(occupation === "Teacher" && pet !== null){ + allTeachers += `${firstName} ${lastName}\n`; + } + } + return allTeachers; +} + +console.log(teacherWithPet(hogwarts)) +console.log(gryffindorforStudent(hogwarts)) \ No newline at end of file From 7155b0bd2a4601a8d504a7cf43568f0b2bfe3b97 Mon Sep 17 00:00:00 2001 From: dona-shehu Date: Wed, 29 Jul 2026 23:26:30 +0100 Subject: [PATCH 3/9] Reversing changes on main. --- Sprint-1/destructuring/exercise-1/exercise.js | 11 ++++---- Sprint-1/destructuring/exercise-2/exercise.js | 26 +------------------ 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index f4e48506..f3eecbd6 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -1,16 +1,15 @@ const personOne = { - firstName: "Popeye", + name: "Popeye", age: 34, favouriteFood: "Spinach", }; - -let {firstName, age, favouriteFood} = personOne + // Update the parameter to this function to make it work. // Don't change anything else. -function introduceYourself() { +function introduceYourself(___________________________) { console.log( - `Hello, my name is ${firstName}. I am ${age} years old and my favourite food is ${favouriteFood}.` + `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` ); } -introduceYourself(personOne); +introduceYourself(personOne); \ No newline at end of file diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index 2852173f..c16caccf 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -69,28 +69,4 @@ let hogwarts = [ pet: "Phoenix", occupation: "Teacher", }, -]; -function gryffindorforStudent(){ - let allStudents = ""; - for(let student of hogwarts){ - let {firstName,lastName,house,pet,occupation} = student; - if (house === "Gryffindor"){ - allStudents += `${firstName} ${lastName}\n` - } - } - return allStudents; -} - -function teacherWithPet(){ - let allTeachers = ""; - for(const person of hogwarts){ - let {firstName, lastName,pet, occupation} = person; - if(occupation === "Teacher" && pet !== null){ - allTeachers += `${firstName} ${lastName}\n`; - } - } - return allTeachers; -} - -console.log(teacherWithPet(hogwarts)) -console.log(gryffindorforStudent(hogwarts)) \ No newline at end of file +]; \ No newline at end of file From 42348b4b72376315e23d24af3c57577f40dedf28 Mon Sep 17 00:00:00 2001 From: dona-shehu Date: Sun, 2 Aug 2026 16:19:48 +0100 Subject: [PATCH 4/9] fixed author ,add closing braked, changed the check to true, changed button name. --- debugging/book-library/script.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d..7e845516 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(); } } @@ -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 @@ -76,7 +76,7 @@ function render() { changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); let readStatus = ""; - if (myLibrary[i].check == false) { + if (myLibrary[i].check == true) { readStatus = "Yes"; } else { readStatus = "No"; @@ -90,11 +90,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 9b12fa38e27c065e333aed7ffb9ae61dda5fce76 Mon Sep 17 00:00:00 2001 From: dona-shehu Date: Sun, 2 Aug 2026 16:45:40 +0100 Subject: [PATCH 5/9] Revert unintended whitespace changes to exercise-1 and exercise-2 --- Sprint-1/destructuring/exercise-1/exercise.js | 2 +- Sprint-1/destructuring/exercise-2/exercise.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index f3eecbd6..1ff2ac5c 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -12,4 +12,4 @@ function introduceYourself(___________________________) { ); } -introduceYourself(personOne); \ No newline at end of file +introduceYourself(personOne); diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index c16caccf..e11b75eb 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -69,4 +69,4 @@ let hogwarts = [ pet: "Phoenix", occupation: "Teacher", }, -]; \ No newline at end of file +]; From 3edd22423b915a64def6221c100293c14ecffe82 Mon Sep 17 00:00:00 2001 From: dona-shehu Date: Mon, 3 Aug 2026 15:23:25 +0100 Subject: [PATCH 6/9] updated index.html following the guide --- debugging/book-library/index.html | 36 ++++++++++--------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71..aa90d8d5 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,12 +1,9 @@ - - + + Book Library + @@ -31,7 +28,7 @@

Library

Library /> Library class="form-control" id="pages" name="pages" + min="1" required /> - +
- @@ -80,17 +74,9 @@

Library

- - - - - - - - - +
- + From 1f6ee386237b49d6aae72cbea299b635738e9736 Mon Sep 17 00:00:00 2001 From: dona-shehu Date: Mon, 3 Aug 2026 15:23:44 +0100 Subject: [PATCH 7/9] updated the script following the guide --- debugging/book-library/script.js | 120 ++++++++++++++----------------- 1 file changed, 55 insertions(+), 65 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 7e845516..be10a8b4 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -6,41 +6,39 @@ 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 + if (myLibrary.length === 0) { + myLibrary.push(new Book("Robison 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(); } } - -const title = document.getElementById("title"); -const author = document.getElementById("author"); -const pages = document.getElementById("pages"); -const check = document.getElementById("check"); +document.getElementById("submitBtn").addEventListener("click", submit); +const titleInput = document.getElementById("title"); +const authorInput = document.getElementById("author"); +const pagesInput = document.getElementById("pages"); +const checkInput = 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, author.value, pages.value, check.checked); - myLibrary.push(book); - render(); + const titleVal = titleInput.value.trim(); + const authorVal = authorInput.value.trim(); + const pagesVal = Number(pagesInput.value); + + if (!titleVal || !pagesVal || pagesVal <= 0) { + alert("Please fill all fields with valid values!"); + return; } + + const book = new Book(titleVal, authorVal, pagesVal, checkInput.checked); + myLibrary.push(book); + render(); + + titleInput.value = ""; + authorInput.value = ""; + pagesInput.value = ""; + checkInput.checked = false; } function Book(title, author, pages, check) { @@ -51,53 +49,45 @@ 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--) { - table.deleteRow(n); - } + const tbody = document.getElementById("displayBody"); + tbody.innerHTML = ""; + //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; + for (let i = 0; i < myLibrary.length; i++) { + const book = myLibrary[i]; + const row = tbody.insertRow(); - //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 == true) { - readStatus = "Yes"; - } else { - readStatus = "No"; - } - changeBut.innerText = readStatus; + 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 = book.title; + authorCell.textContent = book.author; + pagesCell.textContent = book.pages; - changeBut.addEventListener("click", function () { - myLibrary[i].check = !myLibrary[i].check; + //add and wait for action for read/unread button + const markReadButton = document.createElement("button"); + markReadButton.className = "btn btn-success"; + markReadButton.textContent = book.check ? "Yes" : "No"; + markReadButton.addEventListener("click", function () { + book.check = !book.check; render(); }); + wasReadCell.appendChild(markReadButton); + //add delete button to every row and render again - let delButton = document.createElement("button"); - 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}`); + const deleteButton = document.createElement("button"); + deleteButton.className = "btn btn-warning"; + deleteButton.textContent = "Delete"; + deleteButton.addEventListener("click", function () { + const deletedTitle = book.title; myLibrary.splice(i, 1); render(); + console.log(`You've deleted title: ${deletedTitle}`); }); + + deleteCell.appendChild(deleteButton); } } From 0e972b25080a0077d7d58ead19d7978cc69499aa Mon Sep 17 00:00:00 2001 From: dona-shehu Date: Mon, 3 Aug 2026 15:24:00 +0100 Subject: [PATCH 8/9] updated the style following the guide --- debugging/book-library/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debugging/book-library/style.css b/debugging/book-library/style.css index 302950cb..3da9f9cb 100644 --- a/debugging/book-library/style.css +++ b/debugging/book-library/style.css @@ -1,7 +1,7 @@ .form-group { width: 400px; height: 300px; - align-self: left; + align-self: start; padding-left: 20px; } From 89ab4a139b22dfaa4fffe6895683b57157c69e4b Mon Sep 17 00:00:00 2001 From: dona-shehu Date: Mon, 3 Aug 2026 23:09:22 +0100 Subject: [PATCH 9/9] updated the code after review --- debugging/book-library/script.js | 36 +++++++++++++++++++------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index be10a8b4..c75adf62 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,9 +1,8 @@ -let myLibrary = []; - -window.addEventListener("load", function (e) { - populateStorage(); - render(); -}); +const myLibrary = []; +const titleInput = document.getElementById("title"); +const authorInput = document.getElementById("author"); +const pagesInput = document.getElementById("pages"); +const checkInput = document.getElementById("check"); function populateStorage() { if (myLibrary.length === 0) { @@ -13,11 +12,6 @@ function populateStorage() { ); } } -document.getElementById("submitBtn").addEventListener("click", submit); -const titleInput = document.getElementById("title"); -const authorInput = document.getElementById("author"); -const pagesInput = document.getElementById("pages"); -const checkInput = 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 @@ -26,7 +20,7 @@ function submit() { const authorVal = authorInput.value.trim(); const pagesVal = Number(pagesInput.value); - if (!titleVal || !pagesVal || pagesVal <= 0) { + if (!titleVal || pagesVal <= 0 || !Number.isInteger(pagesVal)) { alert("Please fill all fields with valid values!"); return; } @@ -85,9 +79,23 @@ function render() { const deletedTitle = book.title; myLibrary.splice(i, 1); render(); - console.log(`You've deleted title: ${deletedTitle}`); + showMessage(`You've deleted title: ${deletedTitle}`); }); - deleteCell.appendChild(deleteButton); } } + +function showMessage(text) { + const msgDiv = document.createElement("div"); + msgDiv.className = "alert alert-info"; + msgDiv.textContent = text; + document.body.insertBefore(msgDiv, document.getElementById("display")); + setTimeout(() => msgDiv.remove(), 3000); +} + +window.addEventListener("load", function (e) { + populateStorage(); + render(); +}); + +document.getElementById("submitBtn").addEventListener("click", submit);