Skip to content
Closed
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
2 changes: 1 addition & 1 deletion Sprint-1/destructuring/exercise-1/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}.`
);
Expand Down
19 changes: 19 additions & 0 deletions Sprint-1/destructuring/exercise-2/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,22 @@ let hogwarts = [
occupation: "Teacher",
},
];
/* Task 1 */
function houseGryffindorNames(array) {
array.forEach(({ firstName, lastName, house }) => {
if (house === "Gryffindor") {
console.log(firstName, lastName);
}
});
}
houseGryffindorNames(hogwarts);

/* Task 2 */
function teachersPetNames(array) {
array.forEach(({ firstName, lastName, occupation, pet }) => {
if (occupation === "Teacher" && pet !== null) {
console.log(firstName, lastName);
}
});
}
teachersPetNames(hogwarts);
17 changes: 17 additions & 0 deletions Sprint-1/destructuring/exercise-3/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,20 @@ let order = [
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
];

function takeOutOrder(order) {
let totalSum = 0;

console.log("OTY ITEM TOTAL");
order.forEach(({ quantity, itemName, unitPricePence }) => {
const itemTotal = (quantity * unitPricePence) / 100;
totalSum += itemTotal;

console.log(
`${quantity} ${itemName.padEnd(18)} ${itemTotal.toFixed(2)}`
);
});

console.log(`\nTotal: ${totalSum.toFixed(2)}`);
}
takeOutOrder(order);
35 changes: 15 additions & 20 deletions debugging/book-library/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function populateStorage() {
);
myLibrary.push(book1);
myLibrary.push(book2);
render();
}
}

Expand All @@ -29,17 +28,20 @@ const check = document.getElementById("check");
//via Book function and start render function
function submit() {
if (
title.value == null ||
title.value == "" ||
pages.value == null ||
pages.value == ""
title.value.trim() === "" ||
author.value.trim() === "" ||
pages.value.trim() === ""
) {
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();
title.value = "";
author.value = "";
pages.value = "";
check.checked = false;
}
}

Expand All @@ -54,7 +56,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 All @@ -72,15 +74,9 @@ function render() {

//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) {
readStatus = "Yes";
} else {
readStatus = "No";
}
let readStatus = myLibrary[i].check ? "Yes" : "No";
changeBut.innerText = readStatus;

changeBut.addEventListener("click", function () {
Expand All @@ -90,11 +86,10 @@ 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 () {
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();
Expand Down
Loading