Skip to content

Commit b25fa41

Browse files
committed
- Answer the questions in the Readme File.
- Use object destructuring in introduceYourself parameter
1 parent 96ed5c9 commit b25fa41

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const personOne = {
66

77
// Update the parameter to this function to make it work.
88
// Don't change anything else.
9+
// Use object destructuring in introduceYourself parameter
910
function introduceYourself({ name, age, favouriteFood }) {
10-
// Use the destructured variables in the console.log statement.
11-
// Don't change anything else.
11+
1212
console.log(
1313
`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`
1414
);

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,27 @@ console.log(`Batman is ${firstName}, ${lastName}`);
2929

3030
# Exercise
3131

32-
- What is the syntax to destructure the object `personOne` in exercise.js?
33-
- Update the parameter of the function `introduceYourself` to use destructuring on the object that gets passed in.
32+
1 - What is the syntax to destructure the object `personOne` in exercise.js?
33+
34+
For the personOne example, the destructuring syntax would be:
35+
36+
```
37+
let { name, age, favouriteFood } = personOne;
38+
39+
That pulls the three properties out of personOne into separate variables.
40+
41+
```
42+
2 - Update the parameter of the function `introduceYourself` to use destructuring on the object that gets passed in.
43+
44+
```
45+
To update the parameter of introduceYourself function to use destructuring, I would write:
46+
47+
function introduceYourself({ name, age, favouriteFood }) {
48+
console.log(
49+
`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`
50+
);
51+
}
52+
This way, the function immediately unpacks those properties from the object is passed in, without
53+
needing separate variable assignments.
54+
55+
```

0 commit comments

Comments
 (0)