Skip to content

Commit 72f70ef

Browse files
authored
exercise.js
Improve Gryffindor display function for better grammar - Updated pet handling so that the sentence is grammatically correct. - Now only mentions a pet if one exists. - Matches the example style.
1 parent a6639ec commit 72f70ef

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,16 @@ let hogwarts = [
7777
// Use object destructuring to extract the values you need out of each element in the array.
7878

7979
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'}.`);
80+
if (house !== "Gryffindor") return;
81+
82+
let petSentence = pet
83+
? ` I have a ${pet}.`
84+
: "";
85+
86+
console.log(
87+
`Hello, my name is ${firstName} ${lastName}. I am a ${occupation} at Hogwarts and I belong to the ${house} house.${petSentence}`
88+
);
8289
}
83-
hogwarts.forEach(displayGryffindors);
8490

8591
// Write a function named displayGryffindors that takes an object
8692
// with properties `firstName`, `lastName`, `house`, `pet`, and `occupation`

0 commit comments

Comments
 (0)