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)); 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 0; n-- { + for (let n = rowsNumber - 1; n > 0; n--) { table.deleteRow(n); } //insert updated row and cells @@ -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();