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} = personOne) {
console.log(
`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`
);
Expand Down
27 changes: 27 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,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));
12 changes: 12 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,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));
2 changes: 1 addition & 1 deletion debugging/book-library/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title> </title>
<title>My Book Library </title>
<meta
charset="utf-8"
name="viewport"
Expand Down
16 changes: 8 additions & 8 deletions debugging/book-library/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
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 All @@ -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;

Expand All @@ -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();
Expand Down
Loading