From 8afb2772783ad065272bc1bcd6248f782b9df63b Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 14 Feb 2024 22:30:07 +0000 Subject: [PATCH] finished all 3 --- array-destructuring/exercise-1/exercise.js | 2 ++ array-destructuring/exercise-2/exercise.js | 12 ++++++++++++ array-destructuring/exercise-3/exercise.js | 10 ++++++++++ 3 files changed, 24 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}.` diff --git a/array-destructuring/exercise-2/exercise.js b/array-destructuring/exercise-2/exercise.js index e11b75eb..9c5107c5 100644 --- a/array-destructuring/exercise-2/exercise.js +++ b/array-destructuring/exercise-2/exercise.js @@ -70,3 +70,15 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +hogwarts.forEach(({ firstName, lastName, house }) => { + if (house === "Gryffindor"){ + console.log(`Task 1 => ${firstName} ${lastName}`); + } +}); + +hogwarts.forEach(({ firstName, lastName, pet, occupation }) => { + if (occupation === "Teacher" && pet !== null){ + console.log(`Task 2 => ${firstName} ${lastName}`); + } +}); diff --git a/array-destructuring/exercise-3/exercise.js b/array-destructuring/exercise-3/exercise.js index 0a01f8f0..5035098d 100644 --- a/array-destructuring/exercise-3/exercise.js +++ b/array-destructuring/exercise-3/exercise.js @@ -6,3 +6,13 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPrice: 1.0 }, { itemName: "Hash Brown", quantity: 4, unitPrice: 0.4 }, ]; + +let sum = 0; + +order.forEach(({ itemName, quantity, unitPrice }) => { + let total = unitPrice*quantity; + console.log(`${quantity} ${itemName} ${total.toFixed(2)}`); + sum += total; +}); + +console.log(`Total: ${sum}`); \ No newline at end of file