From df7a0ffa679cb2e8c57048ce37fcfae0de67af50 Mon Sep 17 00:00:00 2001 From: aishaathmanlali Date: Tue, 13 Feb 2024 11:33:49 +0100 Subject: [PATCH 1/5] assign value of the object to a variable --- array-destructuring/exercise-1/exercise.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/array-destructuring/exercise-1/exercise.js b/array-destructuring/exercise-1/exercise.js index a6eab299..ee3c1e13 100644 --- a/array-destructuring/exercise-1/exercise.js +++ b/array-destructuring/exercise-1/exercise.js @@ -4,6 +4,8 @@ const personOne = { favouriteFood: "Spinach", }; +let { name, age, favouriteFood } = personOne; + function introduceYourself(___________________________) { console.log( `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` From 8d15a87e71f4b28dc198dc61d3fdab8607aa9135 Mon Sep 17 00:00:00 2001 From: aishaathmanlali Date: Tue, 13 Feb 2024 11:37:00 +0100 Subject: [PATCH 2/5] assign value of the object to a variable --- array-destructuring/exercise-1/exercise.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/array-destructuring/exercise-1/exercise.js b/array-destructuring/exercise-1/exercise.js index ee3c1e13..d81323bc 100644 --- a/array-destructuring/exercise-1/exercise.js +++ b/array-destructuring/exercise-1/exercise.js @@ -6,7 +6,7 @@ const personOne = { let { name, age, favouriteFood } = personOne; -function introduceYourself(___________________________) { +function introduceYourself() { console.log( `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` ); From 92ee8f862c26185b9da8aac78b56b114ab9b455d Mon Sep 17 00:00:00 2001 From: aishaathmanlali Date: Tue, 13 Feb 2024 12:02:59 +0100 Subject: [PATCH 3/5] find names of people who belong to Gryffindor house --- array-destructuring/exercise-2/exercise.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/array-destructuring/exercise-2/exercise.js b/array-destructuring/exercise-2/exercise.js index e11b75eb..69617fa2 100644 --- a/array-destructuring/exercise-2/exercise.js +++ b/array-destructuring/exercise-2/exercise.js @@ -70,3 +70,15 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +function findGryffindor(arr){ + arr.forEach(element => { + let {firstName, lastName, house, pet, occupation} = element; + + if(house === "Gryffindor"){ + console.log(firstName, lastName); + } + }); +} + +findGryffindor(hogwarts); \ No newline at end of file From ca3100d1c9c7ebab1c44f0680f1b0ed9428ff73c Mon Sep 17 00:00:00 2001 From: aishaathmanlali Date: Tue, 13 Feb 2024 12:13:34 +0100 Subject: [PATCH 4/5] find teachers with pets --- array-destructuring/exercise-2/exercise.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/array-destructuring/exercise-2/exercise.js b/array-destructuring/exercise-2/exercise.js index 69617fa2..c279101f 100644 --- a/array-destructuring/exercise-2/exercise.js +++ b/array-destructuring/exercise-2/exercise.js @@ -71,6 +71,8 @@ let hogwarts = [ }, ]; +//Task 1 + function findGryffindor(arr){ arr.forEach(element => { let {firstName, lastName, house, pet, occupation} = element; @@ -81,4 +83,18 @@ function findGryffindor(arr){ }); } -findGryffindor(hogwarts); \ No newline at end of file +findGryffindor(hogwarts); + +// Task 2 + +function findTeachersWithPets(arr){ + arr.forEach(element => { + let {firstName, lastName, house, pet, occupation} = element; + + if(occupation === "Teacher" && pet !== null){ + console.log(firstName, lastName); + } + }); +} + +findTeachersWithPets(hogwarts) \ No newline at end of file From 06b28fbc7e87fe4ddf323d6efe9aba14f797ff59 Mon Sep 17 00:00:00 2001 From: aishaathmanlali Date: Tue, 13 Feb 2024 12:34:28 +0100 Subject: [PATCH 5/5] write a functio to print out the receipt and get the total price --- array-destructuring/exercise-3/exercise.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/array-destructuring/exercise-3/exercise.js b/array-destructuring/exercise-3/exercise.js index 0a01f8f0..14a869f5 100644 --- a/array-destructuring/exercise-3/exercise.js +++ b/array-destructuring/exercise-3/exercise.js @@ -6,3 +6,14 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPrice: 1.0 }, { itemName: "Hash Brown", quantity: 4, unitPrice: 0.4 }, ]; + +console.log("QTY\tITEM\t\t\tTOTAL"); + +order.forEach((item) => { + let { itemName, quantity, unitPrice } = item; + const total = (quantity * unitPrice).toFixed(2); + console.log(`${quantity}\t${itemName.padEnd(20)}${total}`); +}); + +const totalOrderCost = order.reduce((total, item) => total + item.quantity * item.unitPrice, 0).toFixed(2); +console.log(`\nTotal: ${totalOrderCost}`);