diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 1ff2ac5..4220bf3 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 }=personOne) { 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 e11b75e..0c55a6d 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,18 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +// - 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. +function gryffindorMembers(hogwarts) { + return hogwarts.filter(({ house }) => house === "Gryffindor") + .map(({ firstName, lastName }) => `${firstName} ${lastName}`); +} +console.log(gryffindorMembers(hogwarts)); +// - 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. +function teachersWithPets(hogwarts) { + return hogwarts.filter(({ occupation, pet }) => occupation === "Teacher" && pet) + .map(({ firstName, lastName }) => `${firstName} ${lastName}`); +} +console.log(teachersWithPets(hogwarts)); \ No newline at end of file diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4..be2d571 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,25 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; + +//We want to log QTY, ITEM, and TOTAL once at the beginning of the receipt +//Then we want to log each item in the order array, and align the columns +//Finally, we want to log the total price of the order +function printReceipt(order){ + let total=0 + console.log("QTY ITEM TOTAL") + console.log("--------------------------------"); + + order.forEach(({itemName, quantity, unitPricePence})=>{ + let totalItem=quantity*unitPricePence/100 + total+=totalItem + console.log( + `${quantity.toString().padEnd(7)} ${itemName.padEnd(21)} £${totalItem.toFixed(2)}` + ); + }) + console.log(`Total: ${total.toFixed(2)}`) +} +printReceipt(order); +// console.log("QTY ".length) ouais c'est 8 +console.log("ITEM ".length) +// ouais c'est 22 \ No newline at end of file diff --git a/Sprint-1/destructuring/exercise-3/readme.md b/Sprint-1/destructuring/exercise-3/readme.md index 9663f01..f72114b 100644 --- a/Sprint-1/destructuring/exercise-3/readme.md +++ b/Sprint-1/destructuring/exercise-3/readme.md @@ -8,7 +8,6 @@ ## Expected result -``` QTY ITEM TOTAL 1 Hot Cakes 2.32 2 Apple Pie 2.78 @@ -18,4 +17,3 @@ QTY ITEM TOTAL 4 Hash Brown 1.60 Total: 14.50 -```