Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions array-destructuring/exercise-1/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const personOne = {
favouriteFood: "Spinach",
};

function introduceYourself(___________________________) {
function introduceYourself(person) {
console.log(
`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`
`Hello, my name is ${person.name}. I am ${person.age} years old and my favourite food is ${person.favouriteFood}.`
);
}

Expand Down
20 changes: 20 additions & 0 deletions array-destructuring/exercise-2/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,23 @@ let hogwarts = [
occupation: "Teacher",
},
];

function displayGryffindorNames(hogwarts) {
const gryffindorNames = hogwarts
.filter(({ house }) => house === "Gryffindor")
.map(({ firstName, lastName }) => `${firstName} ${lastName}`);

console.log(gryffindorNames.join('\n'));
}

displayGryffindorNames(hogwarts);

function displayTeachersWithPets(hogwarts) {
const teacherNamesWithPets = hogwarts
.filter(({ occupation, pet }) => occupation === "Teacher" && pet)
.map(({ firstName, lastName }) => `${firstName} ${lastName}`);

console.log(teacherNamesWithPets.join('\n'));
}

displayTeachersWithPets(hogwarts);
15 changes: 15 additions & 0 deletions array-destructuring/exercise-3/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,18 @@ let order = [
{ itemName: "Hot Coffee", quantity: 2, unitPrice: 1.0 },
{ itemName: "Hash Brown", quantity: 4, unitPrice: 0.4 },
];

function printReceipt(order) {
console.log("QTY\tITEM\t\t\tTOTAL");
let totalCost = 0;

order.forEach(({ itemName, quantity, unitPrice }) => {
const totalItemPrice = quantity * unitPrice;
totalCost += totalItemPrice;
console.log(`${quantity}\t${itemName}\t${totalItemPrice.toFixed(2)}`);
});

console.log(`\nTotal: ${totalCost.toFixed(2)}`);
}

printReceipt(order);
7 changes: 4 additions & 3 deletions book-library/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ <h1>Library</h1>
<div class="form-group">
<label for="title">Title:</label>
<input
type="title"
type="text"
class="form-control"
id="title"
name="title"
required
/>
<label for="author">Author: </label>
<input
type="author"
type="text"
class="form-control"
id="author"
name="author"
Expand All @@ -58,13 +58,14 @@ <h1>Library</h1>
type="checkbox"
class="form-check-input"
id="check"
value=""
value="read"
/>Read
</label>
<input
type="submit"
value="Submit"
class="btn btn-primary"
id="submitBtn"
onclick="submit();"
/>
</div>
Expand Down
6 changes: 3 additions & 3 deletions book-library/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function submit() {
alert("Please fill all fields!");
return false;
} else {
let book = new Book(title.value, title.value, pages.value, check.checked);
let book = new Book(title.value, author.value, pages.value, check.checked);
library.push(book);
render();
}
Expand All @@ -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
Expand Down Expand Up @@ -94,7 +94,7 @@ function render() {
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();
Expand Down