diff --git a/array-destructuring/exercise-1/exercise.js b/array-destructuring/exercise-1/exercise.js index a6eab299..d5efd2cd 100644 --- a/array-destructuring/exercise-1/exercise.js +++ b/array-destructuring/exercise-1/exercise.js @@ -4,9 +4,9 @@ const personOne = { favouriteFood: "Spinach", }; -function introduceYourself(___________________________) { +function introduceYourself(personOne) { console.log( - `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` + `Hello, my name is ${personOne.name}. I am ${personOne.age} years old and my favourite food is ${personOne.favouriteFood}.` ); } diff --git a/array-destructuring/exercise-2/exercise.js b/array-destructuring/exercise-2/exercise.js index e11b75eb..22d7744c 100644 --- a/array-destructuring/exercise-2/exercise.js +++ b/array-destructuring/exercise-2/exercise.js @@ -70,3 +70,27 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +function displayGryffindorResident() { + const gryffindorOccupant=[] + for (const { firstName, lastName, house} of hogwarts) { + if (house === "Gryffindor") { + gryffindorOccupant.push(`${firstName} ${lastName}`) + + } + } + return gryffindorOccupant; +} + +console.log(displayGryffindorResident()); + +function displayTeacherWithPets() { + const teacherWithPets = []; + for (const {firstName, lastName, pet, occupation} of hogwarts) { + if (occupation === "Teacher" && pet != null) { + teacherWithPets.push(`${firstName} ${lastName}`); + } + } + return teacherWithPets; +} +console.log(displayTeacherWithPets()); \ No newline at end of file diff --git a/array-destructuring/exercise-2/readme.md b/array-destructuring/exercise-2/readme.md index 0cfec3b0..8940e3a2 100644 --- a/array-destructuring/exercise-2/readme.md +++ b/array-destructuring/exercise-2/readme.md @@ -4,7 +4,7 @@ _Need some help? Refresh your memory with [this article](https://www.freecodecam In `exercise.js`, you have an array that contains a list of people who are at Hogwarts School of Witchcraft and Wizardry. For each character you have the following information: - +D'You, 1 second a - First Name - Last Name - School House diff --git a/array-destructuring/exercise-3/exercise.js b/array-destructuring/exercise-3/exercise.js index 0a01f8f0..077b7af9 100644 --- a/array-destructuring/exercise-3/exercise.js +++ b/array-destructuring/exercise-3/exercise.js @@ -6,3 +6,17 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPrice: 1.0 }, { itemName: "Hash Brown", quantity: 4, unitPrice: 0.4 }, ]; + +function printOrder() { + const orderTable = "QTY\t ITEM\t TOTAL\n"; + console.log(`${orderTable}`); + for (const {itemName, quantity, unitPrice} of order) { + const totalItemPrice = (quantity * unitPrice).toFixed(2); + console.log(`${quantity} ${itemName.padEnd(20)} ${totalItemPrice}`); + } + const totalPrice = order.reduce((accumulator, {quantity, unitPrice}) =>{ + return accumulator + quantity * unitPrice; + }, 0) + console.log(`\nTotal: ${totalPrice.toFixed(2)}`); +} +printOrder();