From b2d38d1cc1b350a7ace5883afd9d552a8ddc0889 Mon Sep 17 00:00:00 2001 From: PaulinaWywrot Date: Fri, 9 Jun 2023 06:42:08 +0100 Subject: [PATCH] 3 exercises completed --- array-destructuring/exercise-1/exercise.js | 2 +- array-destructuring/exercise-2/exercise.js | 9 +++++++++ array-destructuring/exercise-3/exercise.js | 12 ++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/array-destructuring/exercise-1/exercise.js b/array-destructuring/exercise-1/exercise.js index a6eab299..1906137a 100644 --- a/array-destructuring/exercise-1/exercise.js +++ b/array-destructuring/exercise-1/exercise.js @@ -4,7 +4,7 @@ const personOne = { 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..2d6812c3 100644 --- a/array-destructuring/exercise-2/exercise.js +++ b/array-destructuring/exercise-2/exercise.js @@ -70,3 +70,12 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +const students = hogwarts.filter(({house}) => house === "Gryffindor"); +students.forEach(({ firstName, lastName }) => { + console.log(`${firstName} ${lastName}`) +}); + +const teachers = hogwarts.filter(({ occupation, pet }) => + occupation === "Teacher" && pet !== null); +teachers.forEach(({ firstName, lastName }) => console.log(`${ firstName } ${ lastName }`)); \ No newline at end of file diff --git a/array-destructuring/exercise-3/exercise.js b/array-destructuring/exercise-3/exercise.js index 0a01f8f0..c755b608 100644 --- a/array-destructuring/exercise-3/exercise.js +++ b/array-destructuring/exercise-3/exercise.js @@ -6,3 +6,15 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPrice: 1.0 }, { itemName: "Hash Brown", quantity: 4, unitPrice: 0.4 }, ]; + +receipt = order.map( + ({itemName, quantity, unitPrice}) => { + return { + QTY: quantity, + ITEM: itemName, + TOTAL: quantity * unitPrice + }; + } +) +console.table(receipt); +receipt = [{QTY: 'QTY', ITEM: 'ITEM', TOTAL: 'TOTAL'}, ...receipt]; \ No newline at end of file