diff --git a/array-destructuring/exercise-1/exercise.js b/array-destructuring/exercise-1/exercise.js index a6eab299..e62de539 100644 --- a/array-destructuring/exercise-1/exercise.js +++ b/array-destructuring/exercise-1/exercise.js @@ -4,10 +4,12 @@ const personOne = { favouriteFood: "Spinach", }; -function introduceYourself(___________________________) { +let { name, age, favouriteFood } = personOne; + +function introduceYourself(personOne) { console.log( `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` ); } -introduceYourself(personOne); +introduceYourself(); diff --git a/array-destructuring/exercise-2/exercise.js b/array-destructuring/exercise-2/exercise.js index e11b75eb..e4ea595b 100644 --- a/array-destructuring/exercise-2/exercise.js +++ b/array-destructuring/exercise-2/exercise.js @@ -70,3 +70,16 @@ let hogwarts = [ occupation: "Teacher", }, ]; + + +hogwarts.forEach(({ firstName, lastName, house })=>{ + if (house === "Gryffindor") { + console.log(`Task 1 => ${firstName} ${lastName}`); + } +}); + +hogwarts.forEach(({ firstName, lastName, pet, occupation }) => { + if (occupation === "Teacher" && pet != null) { + console.log(`Task 2 => ${firstName} ${lastName}`) + } +}); \ No newline at end of file diff --git a/array-destructuring/exercise-3/exercise.js b/array-destructuring/exercise-3/exercise.js index 0a01f8f0..b77f4c66 100644 --- a/array-destructuring/exercise-3/exercise.js +++ b/array-destructuring/exercise-3/exercise.js @@ -6,3 +6,13 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPrice: 1.0 }, { itemName: "Hash Brown", quantity: 4, unitPrice: 0.4 }, ]; + +let sum = 0; + +order.forEach(({ itemName, quantity, unitPrice }) => { + let total = unitPrice * quantity; + console.log(`For ${quantity} ${itemName} the total price is ${total}`); + sum += total; +}); + +console.log(`Total: ${+sum}`); \ No newline at end of file diff --git a/book-library/index.html b/book-library/index.html index 23acfa71..616188fe 100644 --- a/book-library/index.html +++ b/book-library/index.html @@ -1,96 +1,56 @@ - - - - - - - - - - -
-

Library

-

Add books to your virtual library

-
+ + Book Library + + + + + + + + + +
+

Library

+

Add books to your virtual library

+
- + -
-
- - - - - - - - -
+
+
+ + + + + + + +
+
+ + + + + + + + + + + + + +
TitleAuthorNumber of PagesReadDelete
- - - - - - - - - - - - - - - - - - - -
TitleAuthorNumber of PagesRead
+ + - - - + \ No newline at end of file diff --git a/book-library/script.js b/book-library/script.js index dc14a775..5de94a30 100644 --- a/book-library/script.js +++ b/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 @@ -75,12 +75,7 @@ function render() { changeBut.id = i; changeBut.className = "btn btn-success"; cell4.appendChild(changeBut); - let readStatus = ""; - if (myLibrary[i].check == false) { - readStatus = "Yes"; - } else { - readStatus = "No"; - } + let readStatus = myLibrary[i].check ? "No" : "Yes"; changeBut.innerHTML = readStatus; changeBut.addEventListener("click", function () { @@ -89,12 +84,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; cell5.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();