diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 1ff2ac5c..90eb4795 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -6,7 +6,7 @@ const personOne = { // Update the parameter to this function to make it work. // Don't change anything else. -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/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb..34ec7891 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,26 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +let gryffindor = ""; +let teatcherDog = ""; +for (let witcher of hogwarts) { + const { + firstName: name, + lastName: surname, + house, + pet, + occupation, + } = witcher; + + const text = name + " " + surname + "\n"; + if (house === "Gryffindor") { + gryffindor += text; + if (pet && occupation === "Teacher") { + teatcherDog += text; + } + } +} + +console.log(`\nGryffindor Residents:\n${gryffindor}`); +console.log(`\nGryffindor Teacher who has pet:\n${teatcherDog}`); diff --git a/Sprint-1/destructuring/exercise-2/readme.md b/Sprint-1/destructuring/exercise-2/readme.md deleted file mode 100644 index 64b5ab1c..00000000 --- a/Sprint-1/destructuring/exercise-2/readme.md +++ /dev/null @@ -1,37 +0,0 @@ -# Exercise 2 - -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: - -- First Name -- Last Name -- School House -- Pet -- Occupation - -## Task 1 - -- In `exercise.js` write a program that will take the `hogwarts` array as input and display the names of the people who belong to the Gryffindor house. -- Use object destructuring to extract the values you need out of each element in the array. - -### Expected result - -``` -Harry Potter -Ron Weasley -Hermione Granger -Minerva McGonagall -Albus Dumbledore -``` - -## Task 2 - -- In `exercise.js` write a program that will take the `hogwarts` array as input and display the names of teachers who have pets. -- Use object destructuring to extract the values you need out of each element in the array. - -### Expected result - -``` -Albus Dumbledore -``` diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e..3ba41c49 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,13 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; +const setPrice = (pricePence) => (pricePence / 100).toFixed(2) +let total = 0; +console.log(`${("QTY").padEnd(7)}${"ITEM".padEnd( 20)}TOTAL`); +for (let item of order){ + const {itemName, quantity, unitPricePence} = item; + const sousTotal = (quantity * unitPricePence); + total += sousTotal; + console.log(`${(quantity+"").padEnd(7)}${itemName.padEnd(20)}${setPrice(sousTotal)}`); +} +console.log(`\n${("TOTAL").padEnd(26)}${setPrice(total)}`);