diff --git a/week-3/Homework/mandatory/2-exercises/exercise-1/exercise-1.js b/week-3/Homework/mandatory/2-exercises/exercise-1/exercise-1.js index 10b93ba..c9bfe98 100644 --- a/week-3/Homework/mandatory/2-exercises/exercise-1/exercise-1.js +++ b/week-3/Homework/mandatory/2-exercises/exercise-1/exercise-1.js @@ -1,11 +1,14 @@ const personOne = { - name: 'Popeye', - age: 34, - favouriteFood: 'Spinach' -} + name: "Popeye", + age: 34, + favouriteFood: "Spinach", +}; +const { name, age, favouriteFood } = personOne; -function introduceYourself(___________________________) { - console.log (`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`); +function introduceYourself(name, age, favouriteFood) { + console.log( + `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` + ); } -introduceYourself(personOne); \ No newline at end of file +introduceYourself(name, age, favouriteFood); diff --git a/week-3/Homework/mandatory/2-exercises/exercise-2/exercise-2.js b/week-3/Homework/mandatory/2-exercises/exercise-2/exercise-2.js index 0d3ade0..a5fc825 100644 --- a/week-3/Homework/mandatory/2-exercises/exercise-2/exercise-2.js +++ b/week-3/Homework/mandatory/2-exercises/exercise-2/exercise-2.js @@ -9,3 +9,28 @@ let hogwarts = [ { firstName: "Minerva", lastName: "McGonagall", house: "Gryffindor", pet: null, occupation: "Teacher" }, { firstName: "Albus", lastName: "Dumbledore", house: "Gryffindor", pet: "Phoenix", occupation: "Teacher" } ] + +let GryffindorPeople = hogwarts.filter((element) => { + if (element.house === "Gryffindor") { + return true; + } +}); + +let [{ firstName, lastName }] = GryffindorPeople; + +GryffindorPeople.forEach((element) => { + console.log(element.firstName + " " + element.lastName); +}); + +let teacherWithPet = hogwarts.filter((element) => { + if (element.pet !== null && element.occupation === "Teacher") { + return true; + } +}); + +let [{ firstName, lastName }] = teacherWithPet; + +teacherWithPet.forEach((element) => { + console.log(element.firstName + " " + element.lastName); +}); + diff --git a/week-3/Homework/mandatory/2-exercises/exercise-3/exercise-3.js b/week-3/Homework/mandatory/2-exercises/exercise-3/exercise-3.js index b60d527..316440b 100644 --- a/week-3/Homework/mandatory/2-exercises/exercise-3/exercise-3.js +++ b/week-3/Homework/mandatory/2-exercises/exercise-3/exercise-3.js @@ -6,4 +6,39 @@ { itemName: "Hot Coffee", quantity: 2, unitPrice: 1.00}, { itemName: "Hash Brown", quantity: 4, unitPrice: 0.40} ] - \ No newline at end of file + + let order = [ + { itemName: "Hot cakes", quantity: 1, unitPrice: 2.29 }, + { itemName: "Apple Pie", quantity: 2, unitPrice: 1.39 }, + { itemName: "Egg McMuffin", quantity: 1, unitPrice: 2.8 }, + { itemName: "Sausage McMuffin", quantity: 1, unitPrice: 3.0 }, + { itemName: "Hot Coffee", quantity: 2, unitPrice: 1.0 }, + { itemName: "Hash Brown", quantity: 4, unitPrice: 0.4 }, +]; + +let total = 0; +console.log("QTY ITEM TOTAL"); +order.forEach((element) => { + console.log( + element.quantity + + " " + + element.itemName + + " " + + element.quantity * element.unitPrice + ); + total += element.quantity * element.unitPrice; +}); +console.log(" Total: " + total); + +/* +function printReceipt(order) { + let oneOrderKeys = Object.keys(order[0]); + let orderKeys = oneOrderKeys.map(changeCase); + + console.log(orderKeys); +} +function changeCase(word) { + return word.toUpperCase(); +} +printReceipt(order); +*/