Skip to content

London | ITP-May-2025 | Aida Eslamimoghadam | Module-Data-Flows | Sprint 1- feature/destructuring #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
8 changes: 4 additions & 4 deletions Sprint-1/destructuring/exercise-1/exercise.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const personOne = {
name: "Popeye",
age: 34,
favouriteFood: "Spinach",
name: "Aida",
age: 37,
favouriteFood: "Pasta",
};

// 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
31 changes: 31 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,34 @@ let hogwarts = [
occupation: "Teacher",
},
];


function studentInfo(hogwarts)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code works correctly here, but it is a bit difficult to read with how it is laid out. Can you see any ways you could improve the code style and readability?

{
hogwarts.forEach(person => {
const{firstName,lastName,house}=person;
if(house=="Gryffindor")
console.log(firstName,lastName)

});
}

function petOwner(hogwarts){
hogwarts.forEach(person=>
{
const{firstName,lastName,occupation,pet}=person;
if (occupation=="Teacher" && pet!=null)
console.log(firstName,lastName)

}
)
}


console.log("Display the names of the people who belong to the Gryffindor house: ")
studentInfo(hogwarts)


console.log("\nDisplay the names of teachers who have pets:")
petOwner(hogwarts)
27 changes: 27 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,30 @@ let order = [
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
];



function printReceipt(order) {
let total = 0;
console.log("QTY ITEM TOTAL");
order.forEach(record => {
const { itemName, quantity, unitPricePence } = record;
const lineTotal = quantity * unitPricePence;
total += lineTotal;

console.log(
String(quantity).padEnd(5) +
itemName.padEnd(20) +
convertPenceToPound(lineTotal).padStart(6)
);
});

console.log("\nTotal: " + convertPenceToPound(total));
}

function convertPenceToPound(pence) {
const pounds = Number(pence) / 100;
return pounds.toFixed(2);
}

printReceipt(order);