Skip to content
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
3 changes: 2 additions & 1 deletion Sprint-1/destructuring/exercise-1/exercise.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

const personOne = {
name: "Popeye",
age: 34,
favouriteFood: "Spinach",
};

let {name,age,favouriteFood} = personOne;
// Update the parameter to this function to make it work.
// Don't change anything else.
function introduceYourself(___________________________) {
Expand Down
37 changes: 37 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,40 @@ let hogwarts = [
occupation: "Teacher",
},
];


function gryffindorOccupiers(obj) {
const result = [];

for (let person of obj) {
const { firstName, lastName, house } = person;

if (house === "Gryffindor") {
result.push(`${firstName} ${lastName}`);
}
}

return result;
}

console.log(gryffindorOccupiers(hogwarts));


// task 2

function teachersWithPets(hogwarts) {
const result = [];

for (let person of hogwarts) {
const { firstName, lastName, occupation, pet } = person;

if (occupation === "Teacher" && pet) {
result.push(`${firstName} ${lastName}`);
}
}

return result;
}

console.log(teachersWithPets(hogwarts));

21 changes: 21 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,24 @@ let order = [
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
];


console.log("QTY ITEM TOTAL");

let grandTotal = 0;

for (let item of order) {
// Object destructuring
const { itemName, quantity, unitPricePence } = item;
const total = (unitPricePence / 100) * quantity;
grandTotal += total; // the price is in pence so divide by 100 to get pounce equivalent,

// Format each line
const qtyStr = String(quantity).padEnd(7);
const itemStr = itemName.padEnd(20);
const totalStr = total.toFixed(2);

console.log(`${qtyStr}${itemStr}${totalStr}`);
}

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