diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 1ff2ac5c..acff8b7b 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -6,7 +6,9 @@ const personOne = { // Update the parameter to this function to make it work. // Don't change anything else. -function introduceYourself(___________________________) { + +let {name,age,favouriteFood} = personOne; +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..8bb81c33 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,12 @@ let hogwarts = [ occupation: "Teacher", }, ]; +function getFilteredNames(hogwarts) +{ + + let filterName =hogwarts.filter(({house})=>house==="Gryffindor").map(({firstName,lastName})=> `${firstName} ${lastName}`); + console.log(filterName); + let teachersWithPet = hogwarts.filter(({pet,occupation})=> pet!==null && occupation === "Teacher").map(({firstName,lastName})=>`${firstName} ${lastName}`); + console.log(teachersWithPet) +} + getFilteredNames(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 b3a36f4e..d0cf08ac 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,26 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; + +function printReceipt(order) +{ + let sum = 0; + console.log("QTY".padEnd(5) + "ITEM".padEnd(20) + "TOTAL".padStart(10)); + for (const { itemName, quantity, unitPricePence } of order) { + let paddedPrice = unitPricePence.toString().padStart(3, "0"); + let pounds = paddedPrice.slice(0, 1); + let pence = paddedPrice.slice(1).padEnd(2, "0"); + let total = `${pounds}.${pence}` * quantity; + let price = total.toFixed(2); + sum += total; + let result = + String(quantity).padEnd(5) + itemName.padEnd(20) + price.padStart(10); + console.log(result); + } + console.log(); + return `Total: ${sum.toFixed(2)}`; + +} + + +console.log(printReceipt(order)); \ No newline at end of file diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71..62664a01 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -65,7 +65,7 @@