Skip to content

Commit 283f63e

Browse files
committed
- Write a function named displayGryffindors that takes an object. with properties firstName, lastName, house, pet, and occupation and display the names of the people who belong to the Gryffindor house.
1 parent b25fa41 commit 283f63e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-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+
75+
// write a program that will take the `hogwarts` array as
76+
// input and display the names of the people who belong to the Gryffindor house.
77+
// Use object destructuring to extract the values you need out of each element in the array.
78+
79+
function displayGryffindors({ firstName, lastName, house, pet, occupation }) {
80+
if (house !== "Gryffindor") return;
81+
console.log(`Hello, my name is ${firstName} ${lastName}. I am a ${occupation} at Hogwarts and I belong to the ${house} house. My pet is a ${pet ? pet : 'none'}.`);
82+
}
83+
hogwarts.forEach(displayGryffindors);
84+
85+
// Write a function named displayGryffindors that takes an object
86+
// with properties `firstName`, `lastName`, `house`, `pet`, and `occupation`
87+
// and display the names of the people who belong to the Gryffindor house.
88+

Sprint-1/destructuring/exercise-2/readme.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,18 @@ Albus Dumbledore
3333
### Expected result
3434

3535
```
36+
37+
Hello, my name is Harry Potter. I am a Student at Hogwarts and I belong to the Gryffindor house.
38+
I have a pet Owl.
39+
Hello, my name is Ron Weasley. I am a Student at Hogwarts and I belong to the Gryffindor house.
40+
I have a pet Scabbers.
41+
Hello, my name is Hermione Granger. I am a Student at Hogwarts and I belong to the Gryffindor house.
42+
I have a pet Cat.
43+
Hello, my name is Minerva McGonagall. I am a Teacher at Hogwarts and I belong to the Gryffindor house.
44+
I don't have a pet.
45+
Hello, my name is Albus Dumbledore. I am a Teacher at Hogwarts and I belong to the Gryffindor house.
46+
I have a pet Phoenix.
47+
48+
3649
Albus Dumbledore
3750
```

0 commit comments

Comments
 (0)