From 14f15f32a6116071eeb610283efbf17ee088ada4 Mon Sep 17 00:00:00 2001 From: Sariat Date: Sat, 3 Feb 2024 15:29:48 +0000 Subject: [PATCH 1/5] I added the object to the key --- array-destructuring/exercise-1/exercise.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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}.` ); } From fb5f51e11be147c1b707b0356ec33ddff8cfaac6 Mon Sep 17 00:00:00 2001 From: Sariat Date: Tue, 13 Feb 2024 22:07:24 +0000 Subject: [PATCH 2/5] I created the first functionality that returns the occupant name --- array-destructuring/exercise-2/exercise.js | 13 +++++++++++++ array-destructuring/exercise-2/readme.md | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/array-destructuring/exercise-2/exercise.js b/array-destructuring/exercise-2/exercise.js index e11b75eb..165e9544 100644 --- a/array-destructuring/exercise-2/exercise.js +++ b/array-destructuring/exercise-2/exercise.js @@ -70,3 +70,16 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +function displayGryffindorResident() { + const gryffindorOccupant=[] + for (const { firstName, lastName, house, pet, occupation} of hogwarts) { + if (house === "Gryffindor") { + gryffindorOccupant.push(`${firstName} ${lastName}`) + + } + } + return gryffindorOccupant; +} + +console.log(displayGryffindorResident()); 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 From dc834f8b40b8eb35097d8ae6fe686b67ffe9d283 Mon Sep 17 00:00:00 2001 From: Sariat Date: Tue, 13 Feb 2024 22:10:00 +0000 Subject: [PATCH 3/5] I created the second functionality that returns the teacher with pets --- array-destructuring/exercise-2/exercise.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/array-destructuring/exercise-2/exercise.js b/array-destructuring/exercise-2/exercise.js index 165e9544..b2f1f1e5 100644 --- a/array-destructuring/exercise-2/exercise.js +++ b/array-destructuring/exercise-2/exercise.js @@ -83,3 +83,14 @@ function displayGryffindorResident() { } console.log(displayGryffindorResident()); + +function displayTeacherWithPets() { + const teacherWithPets = []; + for (const {firstName, lastName, house, pet, occupation} of hogwarts) { + if (occupation === "Teacher" && pet != null) { + teacherWithPets.push(`${firstName} ${lastName}`); + } + } + return teacherWithPets; +} +console.log(displayTeacherWithPets()); \ No newline at end of file From c3b62418c4d4daf33b1e56223846545ecb980c12 Mon Sep 17 00:00:00 2001 From: Sariat Date: Tue, 13 Feb 2024 23:04:38 +0000 Subject: [PATCH 4/5] I created the functionality to print order and return the total price --- array-destructuring/exercise-3/exercise.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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(); From 07a6cd8278f867819575ca5c352e75b48d432efa Mon Sep 17 00:00:00 2001 From: Sariat Date: Tue, 13 Feb 2024 23:33:26 +0000 Subject: [PATCH 5/5] I removed the unnecessary variables from the function --- array-destructuring/exercise-2/exercise.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/array-destructuring/exercise-2/exercise.js b/array-destructuring/exercise-2/exercise.js index b2f1f1e5..22d7744c 100644 --- a/array-destructuring/exercise-2/exercise.js +++ b/array-destructuring/exercise-2/exercise.js @@ -73,7 +73,7 @@ let hogwarts = [ function displayGryffindorResident() { const gryffindorOccupant=[] - for (const { firstName, lastName, house, pet, occupation} of hogwarts) { + for (const { firstName, lastName, house} of hogwarts) { if (house === "Gryffindor") { gryffindorOccupant.push(`${firstName} ${lastName}`) @@ -86,7 +86,7 @@ console.log(displayGryffindorResident()); function displayTeacherWithPets() { const teacherWithPets = []; - for (const {firstName, lastName, house, pet, occupation} of hogwarts) { + for (const {firstName, lastName, pet, occupation} of hogwarts) { if (occupation === "Teacher" && pet != null) { teacherWithPets.push(`${firstName} ${lastName}`); }