Skip to content

Commit efa5ce8

Browse files
committed
Filter and display Gryffindor members and teachers with pets using object destructuring
1 parent 41ddcad commit efa5ce8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Sprint-1/destructuring/exercise-2/exercise.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,19 @@ let hogwarts = [
7070
occupation: "Teacher",
7171
},
7272
];
73+
74+
// Task 1: Display names of people in Gryffindor
75+
hogwarts.forEach(({ firstName, lastName, house }) => {
76+
if (house === "Gryffindor") {
77+
console.log(`${firstName} ${lastName}`);
78+
}
79+
});
80+
81+
console.log(""); // Just to separate the two outputs
82+
83+
// Task 2: Display names of teachers who have pets
84+
hogwarts.forEach(({ firstName, lastName, pet, occupation }) => {
85+
if (occupation === "Teacher" && pet) {
86+
console.log(`${firstName} ${lastName}`);
87+
}
88+
});

0 commit comments

Comments
 (0)