diff --git a/array-destructuring/exercise-1/exercise.js b/array-destructuring/exercise-1/exercise.js index a6eab299..e996e93b 100644 --- a/array-destructuring/exercise-1/exercise.js +++ b/array-destructuring/exercise-1/exercise.js @@ -1,10 +1,11 @@ + const personOne = { name: "Popeye", age: 34, favouriteFood: "Spinach", }; -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/array-destructuring/exercise-2/exercise.js b/array-destructuring/exercise-2/exercise.js index e11b75eb..b6ab5017 100644 --- a/array-destructuring/exercise-2/exercise.js +++ b/array-destructuring/exercise-2/exercise.js @@ -70,3 +70,13 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +console.log('The names of the people who belong to the Gryffindor house:') + +hogwarts.filter(({house}) => house === "Gryffindor") +.forEach(({firstName,lastName}) => console.log(`${firstName} ${lastName}`)); + +console.log('The names of teachers who have pets:') + +hogwarts.filter(({pet,occupation})=> pet !== null && occupation === "Teacher" ) +.forEach(({firstName,lastName}) => console.log(`${firstName} ${lastName}`)); diff --git a/array-destructuring/exercise-3/exercise.js b/array-destructuring/exercise-3/exercise.js index 0a01f8f0..a9d8eb33 100644 --- a/array-destructuring/exercise-3/exercise.js +++ b/array-destructuring/exercise-3/exercise.js @@ -6,3 +6,19 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPrice: 1.0 }, { itemName: "Hash Brown", quantity: 4, unitPrice: 0.4 }, ]; + +function formatPrice(price) { + return price.toFixed(2); +} + +console.log("QTY\tITEM\t\t\tTOTAL"); + +let total = 0; + +for (const {quantity, itemName, unitPrice} of order) { + console.log(`${quantity}\t${itemName}\t\t${(unitPrice * quantity).toFixed(2)}`); + total += unitPrice * quantity; +} + +console.log("\nTotal:", formatPrice(total)); + diff --git a/programmer-humour/index.html b/programmer-humour/index.html new file mode 100644 index 00000000..8f3e8c59 --- /dev/null +++ b/programmer-humour/index.html @@ -0,0 +1,28 @@ + + + +
+ + +