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(personOne) {
console.log(
`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`
`Hello, my name is ${personOne.name}. I am ${personOne.age} years old and my favourite food is ${personOne.favouriteFood}.`
);
}

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

function displayGryffindorResident() {
const gryffindorOccupant=[]
for (const { firstName, lastName, house} of hogwarts) {
if (house === "Gryffindor") {
gryffindorOccupant.push(`${firstName} ${lastName}`)

}
}
return gryffindorOccupant;
}

console.log(displayGryffindorResident());

function displayTeacherWithPets() {
const teacherWithPets = [];
for (const {firstName, lastName, pet, occupation} of hogwarts) {
if (occupation === "Teacher" && pet != null) {
teacherWithPets.push(`${firstName} ${lastName}`);
}
}
return teacherWithPets;
}
console.log(displayTeacherWithPets());
2 changes: 1 addition & 1 deletion array-destructuring/exercise-2/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ _Need some help? Refresh your memory with [this article](https://www.freecodecam

In `exercise.js`, you have an array that contains a list of people who are at Hogwarts School of Witchcraft and Wizardry.
For each character you have the following information:

D'You, 1 second a
- First Name
- Last Name
- School House
Expand Down
14 changes: 14 additions & 0 deletions array-destructuring/exercise-3/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,17 @@ let order = [
{ itemName: "Hot Coffee", quantity: 2, unitPrice: 1.0 },
{ itemName: "Hash Brown", quantity: 4, unitPrice: 0.4 },
];

function printOrder() {
const orderTable = "QTY\t ITEM\t TOTAL\n";
console.log(`${orderTable}`);
for (const {itemName, quantity, unitPrice} of order) {
const totalItemPrice = (quantity * unitPrice).toFixed(2);
console.log(`${quantity} ${itemName.padEnd(20)} ${totalItemPrice}`);
}
const totalPrice = order.reduce((accumulator, {quantity, unitPrice}) =>{
return accumulator + quantity * unitPrice;
}, 0)
console.log(`\nTotal: ${totalPrice.toFixed(2)}`);
}
printOrder();