diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000..25549074 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + "recommendations": [ + "esbenp.prettier-vscode", + "dbaeumer.vscode-eslint", + "streetsidesoftware.code-spell-checker", + "eamodio.gitlens", + "ritwickdey.LiveServer", + "vsliveshare.vsliveshare" + ] +} diff --git a/object-destructuring/exercise-1/exercise.js b/object-destructuring/exercise-1/exercise.js index a6eab299..1927a0ac 100644 --- a/object-destructuring/exercise-1/exercise.js +++ b/object-destructuring/exercise-1/exercise.js @@ -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}.` ); diff --git a/object-destructuring/exercise-2/exercise.js b/object-destructuring/exercise-2/exercise.js index e11b75eb..381a9cf0 100644 --- a/object-destructuring/exercise-2/exercise.js +++ b/object-destructuring/exercise-2/exercise.js @@ -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); \ No newline at end of file diff --git a/object-destructuring/exercise-3/exercise.js b/object-destructuring/exercise-3/exercise.js index 0a01f8f0..805f02c3 100644 --- a/object-destructuring/exercise-3/exercise.js +++ b/object-destructuring/exercise-3/exercise.js @@ -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); \ No newline at end of file