From a0113fe114b34b508126994fa889b3b24b07c773 Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 26 Mar 2026 15:08:29 +0000 Subject: [PATCH 1/8] sprint-1 --- Sprint-1/destructuring/exercise-1/exercise.js | 2 +- Sprint-1/destructuring/exercise-2/exercise.js | 26 +++++++++++++++++ Sprint-1/destructuring/exercise-3/exercise.js | 29 +++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 1ff2ac5c..90eb4795 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}) { 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..32f7b126 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,29 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +function nameAndHoues(arr){ + let namesOfGryffindor ="" +for ( let i =0; i Date: Mon, 30 Mar 2026 19:29:34 +0100 Subject: [PATCH 2/8] for fixed --- Sprint-1/destructuring/exercise-2/exercise.js | 4 ++-- debugging/book-library/script.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index 32f7b126..7119cfc0 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -73,8 +73,8 @@ let hogwarts = [ function nameAndHoues(arr){ let namesOfGryffindor ="" -for ( let i =0; i 0; n-- { + for (let n = rowsNumber) - 1; n > 0; n-- { table.deleteRow(n); } //insert updated row and cells From 10b75aed2e606e858e7d776ff8129a4e102634e0 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 30 Mar 2026 19:35:54 +0100 Subject: [PATCH 3/8] indentation tidyed up --- Sprint-1/destructuring/exercise-2/exercise.js | 28 +++++++++---------- Sprint-1/destructuring/exercise-3/exercise.js | 2 +- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index 7119cfc0..3189b381 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -71,28 +71,26 @@ let hogwarts = [ }, ]; -function nameAndHoues(arr){ - let namesOfGryffindor ="" -for ( pepole of hogwarts){ - const { firstName, house,lastName} = pepole - if (house === "Gryffindor"){ - namesOfGryffindor += `${firstName} ${lastName}\n` - +function nameAndHoues(arr) { + let namesOfGryffindor = ""; + for (pepole of hogwarts) { + const { firstName, house, lastName } = pepole; + if (house === "Gryffindor") { + namesOfGryffindor += `${firstName} ${lastName}\n`; + } } -} -return namesOfGryffindor + return namesOfGryffindor; } function staffPets(arr) { - let namesOfTeachersPets ="" + let namesOfTeachersPets = ""; for (let i = 0; i < arr.length; i++) { const { firstName, pet, occupation, lastName } = arr[i]; if (occupation == "Teacher" && pet !== null) - namesOfTeachersPets += `${firstName} ${lastName}` + namesOfTeachersPets += `${firstName} ${lastName}`; } - return namesOfTeachersPets + return namesOfTeachersPets; } - -console.log(nameAndHoues(hogwarts)) -console.log(staffPets(hogwarts)) +console.log(nameAndHoues(hogwarts)); +console.log(staffPets(hogwarts)); diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index 38574b3c..3909d7dc 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -26,7 +26,7 @@ function receipt(arr){ totals = quantity + itemName + unitPricePenceAsCash // totals = `${quantity} ${itemName} ${unitPricePenceAsCash}` - console.log("%c",totals,"font-size: 28pt") + console.log("%c",totals, ); } From 12032c5077e00138bbfe8ce058c5a65b04d52cfe Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 30 Mar 2026 19:36:55 +0100 Subject: [PATCH 4/8] same --- Sprint-1/destructuring/exercise-3/exercise.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index 3909d7dc..c6f8eaed 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -8,13 +8,13 @@ let order = [ ]; -function receipt(arr){ + function receipt(arr){ - let totalPrice =0 - let subTotal = 0 - let totals ="" - for(let i=0; i Date: Mon, 30 Mar 2026 19:42:31 +0100 Subject: [PATCH 5/8] fix --- 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 a6a5491d..75ce6c1d 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 22c1f438bf78e2fd8c6449e702d9aef976ea6017 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 31 Mar 2026 11:02:05 +0100 Subject: [PATCH 6/8] codeblock tidyed up --- Sprint-1/destructuring/exercise-3/exercise.js | 39 ++++++++----------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index c6f8eaed..95123a5b 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -7,31 +7,24 @@ let order = [ { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; +function receipt(arr) { + let totalPrice = 0; + let subTotal = 0; + let totals = ""; + for (let i = 0; i < order.length; i++) { + const { itemName, quantity, unitPricePence } = arr[i]; - function receipt(arr){ + subTotal = unitPricePence * quantity; + let unitPricePenceAsCash = unitPricePence / 100; + unitPricePenceAsCash = unitPricePenceAsCash.toFixed(2); + totalPrice += subTotal; - let totalPrice =0 - let subTotal = 0 - let totals ="" - for(let i=0; i Date: Sat, 11 Apr 2026 16:35:01 +0100 Subject: [PATCH 7/8] librery changes --- debugging/book-library/script.js | 61 ++++++++++++++++++-------------- debugging/code-reading/readme.md | 9 +++++ hahaha/index.html | 5 +++ hahaha/script.js | 0 hahaha/style.css | 0 5 files changed, 49 insertions(+), 26 deletions(-) create mode 100644 hahaha/index.html create mode 100644 hahaha/script.js create mode 100644 hahaha/style.css diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d..eb76c468 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -5,41 +5,49 @@ window.addEventListener("load", function (e) { render(); }); + + + function populateStorage() { - if (myLibrary.length == 0) { + 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(); + "Ernest Hemingway", "5", true); + myLibrary.push(book1, 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() { + const title = document.getElementById("title").value; + const author = document.getElementById("author").value; + const pages = document.getElementById("pages").value; + const check = document.getElementById("check").checked; if ( - title.value == null || - title.value == "" || - pages.value == null || - pages.value == "" - ) { + + title == "" || + pages == ""|| + author == ""|| + check == "") + + { alert("Please fill all fields!"); - return false; + return true; } else { - let book = new Book(title.value, title.value, pages.value, check.checked); - library.push(book); + let book = new Book(title, author, pages, check); + myLibrary.push(book); render(); + //clear the input values + + } } @@ -54,12 +62,12 @@ 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 - let length = myLibrary.length; - for (let i = 0; i < length; i++) { + 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); @@ -70,13 +78,15 @@ function render() { 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) { + if (myLibrary[i].check != false) { readStatus = "Yes"; } else { readStatus = "No"; @@ -84,7 +94,7 @@ function render() { changeBut.innerText = readStatus; changeBut.addEventListener("click", function () { - myLibrary[i].check = !myLibrary[i].check; + myLibrary[i].check = myLibrary[i].check; render(); }); @@ -100,4 +110,3 @@ function render() { render(); }); } -} diff --git a/debugging/code-reading/readme.md b/debugging/code-reading/readme.md index 4090c14c..4ccd7786 100644 --- a/debugging/code-reading/readme.md +++ b/debugging/code-reading/readme.md @@ -16,6 +16,8 @@ Take a look at the following code: ``` Explain why line 5 and line 8 output different numbers. +line 5 logs the "let x" from the local scope of the function +where as line 8 uses the "let x" from line one in the global scope ## Question 2 @@ -34,6 +36,13 @@ console.log(y); ``` What will be the output of this code. Explain your answer in 50 words or less. +you will get +10 +undefined +undefined +the x is in the global scope so accsesable to f1 +f1 has no return value to log +and the y is only in the local scope of the function ## Question 3 diff --git a/hahaha/index.html b/hahaha/index.html new file mode 100644 index 00000000..e562be63 --- /dev/null +++ b/hahaha/index.html @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/hahaha/script.js b/hahaha/script.js new file mode 100644 index 00000000..e69de29b diff --git a/hahaha/style.css b/hahaha/style.css new file mode 100644 index 00000000..e69de29b From 1d95a3cba132e8b777e6c14f0925a1680f5beeca Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 16 Apr 2026 12:02:18 +0100 Subject: [PATCH 8/8] page now works as expected --- debugging/book-library/script.js | 38 ++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index eb76c468..36c4945a 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -35,8 +35,8 @@ function submit() { title == "" || pages == ""|| - author == ""|| - check == "") + author == "" + ) { alert("Please fill all fields!"); @@ -64,10 +64,15 @@ function render() { //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); @@ -77,8 +82,11 @@ function render() { titleCell.innerHTML = myLibrary[i].title; authorCell.innerHTML = myLibrary[i].author; pagesCell.innerHTML = myLibrary[i].pages; + + //deleteCell.innerHTML = delBut[i] - } + + //add and wait for action for read/unread button let changeBut = document.createElement("button"); @@ -86,7 +94,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"; @@ -94,19 +102,25 @@ function render() { changeBut.innerText = readStatus; changeBut.addEventListener("click", function () { - myLibrary[i].check = myLibrary[i].check; - render(); - }); + if( myLibrary[i].check == true){ + myLibrary[i].check = false; + } + else { + myLibrary[i].check = true; + } + + render(); + }); //add delete button to every row and render again - let delButton = document.createElement("button"); - delBut.id = i + 5; + let delBut = document.createElement("button"); + delBut.id = i ; 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(); - }); + })}; }