Skip to content
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

class-jul2024-1| Syed Arslan Haider | Module-JS3 | WEEK 3 |Array Destructuring #59

Open
wants to merge 5 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
10 changes: 10 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"streetsidesoftware.code-spell-checker",
"eamodio.gitlens",
"ritwickdey.LiveServer",
"vsliveshare.vsliveshare"
]
}
2 changes: 1 addition & 1 deletion object-destructuring/exercise-1/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const personOne = {
favouriteFood: "Spinach",
};

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
20 changes: 20 additions & 0 deletions object-destructuring/exercise-2/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,23 @@ let hogwarts = [
occupation: "Teacher",
},
];

function display_Gryffindor_house_person(hogwarts){
hogwarts.forEach(({firstName,lastName,house,pet}) => {
if(house === "Gryffindor"){
console.log(`${firstName} ${lastName}`);
}
});
}

function people_have_pet(hogwarts){
console.log("people that have pet");
hogwarts.forEach(({firstName,lastName,pet}) => {
if(pet !== null){
console.log(`${firstName} ${lastName}`);
}
});
}

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

function order_receipt(order) {
console.log("Qnt ITEM UNIT PRICE");
let totalPrice = 0;

order.forEach(({ itemName, quantity, unitPrice }) => {
const itemTotal = quantity * unitPrice;
totalPrice += itemTotal;
console.log(
`${String(quantity).padEnd(8)}${itemName.padEnd(20)}${unitPrice.toFixed()}`
);
});

console.log(`\nTotal: ${totalPrice.toFixed(2)}`);
}
order_receipt(order);