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 @@ + + + + + + + Programmer Humour + + + + + +
+

xkcd Comic Viewer

+
+
+ +
+ + + + + \ No newline at end of file diff --git a/programmer-humour/script.js b/programmer-humour/script.js new file mode 100644 index 00000000..37181324 --- /dev/null +++ b/programmer-humour/script.js @@ -0,0 +1,18 @@ +document.addEventListener("DOMContentLoaded", function () { + fetchComic(); +}); + +function fetchComic() { + fetch("https://xkcd.now.sh/?comic=latest") + .then((response) => response.json()) + .then((data) => { + console.log(data); + + const comicContainer = document.getElementById("comicContainer"); + const imgElement = document.createElement("img"); + imgElement.src = data.img; + imgElement.alt = data.alt; + comicContainer.appendChild(imgElement); + }) + .catch((error) => console.error("Error fetching comic:", error)); +} diff --git a/programmer-humour/styles.css b/programmer-humour/styles.css new file mode 100644 index 00000000..f838d55b --- /dev/null +++ b/programmer-humour/styles.css @@ -0,0 +1,37 @@ +body { + font-family: Arial, sans-serif; + margin: 20px; +} + +.container { + max-width: 800px; + margin: 0 auto; + text-align: center; +} + +h1 { + color: aliceblue; + max-width: 100%; + padding: 10px; + background-color: #c24242; + +} + +img { + max-width: 100%; + height: auto; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + background-color: #c24242; + padding: 2rem; + +} + +footer { + color: aliceblue; + padding: 1px; + max-width: 100%; + border: solid 2px #c24242; + margin-top: 10px; + background-color: #c24242; + +} \ No newline at end of file