diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 1ff2ac5c..8d2b393c 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -3,10 +3,10 @@ const personOne = { age: 34, favouriteFood: "Spinach", }; - +let { name, age, favouriteFood } = personOne; // Update the parameter to this function to make it work. // Don't change anything else. -function introduceYourself(___________________________) { +function introduceYourself(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 e11b75eb..7f4602a3 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", }, ]; +function houseGryffindor(hogwarts) { + for (let individualHogwarts of hogwarts) { + if (individualHogwarts.house === "Gryffindor") { + let { firstName, lastName } = individualHogwarts; + console.log(`${firstName} ${lastName}`); + } + } +} +console.log("`````"); +houseGryffindor(hogwarts); +console.log("`````"); + +function teacherWithPets(hogwarts) { + for (let singlePerson of hogwarts) { + if (singlePerson.occupation === "Teacher" && singlePerson.pet !== null) { + let { firstName, lastName } = singlePerson; + console.log(`${firstName} ${lastName}`); + } + } +} +console.log("`````"); +teacherWithPets(hogwarts); +console.log("`````"); diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e..1dc0e245 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 }, ]; +console.log("QTY".padEnd(5) + "ITEM".padEnd(22) + "TOTAL"); + +let grandTotal = 0; + +function valueProperty(order) { + for (let singleOrder of order) { + let { itemName, quantity, unitPricePence } = singleOrder; + + let itemTotal = quantity * unitPricePence; + grandTotal += itemTotal; + + console.log( + String(quantity).padEnd(5) + + itemName.padEnd(22) + + (itemTotal / 100).toFixed(2) + ); + } + + console.log("---------------------------"); + console.log("Total: " + (grandTotal / 100).toFixed(2)); +} + +valueProperty(order);