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 3 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 array-destructuring/exercise-1/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const personOne = {
favouriteFood: "Spinach",
};

function introduceYourself(___________________________) {
function introduceYourself(person) {
let { name, age, favouriteFood } = person;
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 array-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",
},
];

function showPeopleBelongIn(array, houseName) {
const filteredArray = array.filter((person) => person.house === houseName);
filteredArray.forEach((person) => {
const {firstName, lastName} = person;
console.log(`${firstName} ${lastName}`);
})
}

function showTeachersWithPets(array) {
const filteredArray = array.filter((person) => person.pet !== null && person.occupation === "Teacher");
filteredArray.forEach((person) => {
const {firstName, lastName} = person
console.log(`\n${firstName} ${lastName}`);
})
}

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

function makeReceipt(order) {
let total = 0;
let itemNameArray = []
let quantityArray = []
let itemPriceArray = []

order.map((item) => {
const { itemName, quantity, unitPrice } = item;
total += quantity * unitPrice;
quantityArray.push(quantity);
itemNameArray.push(itemName);
itemPriceArray.push(quantity * unitPrice);
})

console.log(`QTY ITEM TOTAL`);

itemNameArray.forEach((itemName, index) => {
const spaces = " ".repeat(20 - itemName.length);
console.log(`${quantityArray[index]} ${itemName}${spaces}$${itemPriceArray[index].toFixed(2)}`);
})

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

makeReceipt(order);