-3
> Locate the `displayBirthdate` function you initially defined, which took no parameter. Modify it to use object de-structuring to get just the 'dob' property of the parameter object it will receive

here's the code 
```javascript
const displayBirthdate = () => {};   
const displayAddress = () => {};  
const displayExtraUserInfo = (extra) => {  
    document.getElementById("btn-birthdate").addEventListener("click", ()=>   
        { displayBirthdate(extra) })
    document.getElementById("btn-phone").addEventListener("click", () => 
        { displayPhone(extra) }) 
    document.getElementById("btn-address").addEventListener("click", () => 
        { displayAddress(extra) })
```

adding to the above question this is the expected response passed as parameter extra

{
  "results": [
    {
      "gender": "female",
      "name": {
        "title": "ms",
        "first": "ceyhan",
        "last": "dizdar"
      },
      "location": {
        "street": "3826 şehitler cd",
        "city": "tekirdağ",
        "state": "bitlis",
        "postcode": 11689,
        "coordinates": {
          "latitude": "79.1017",
          "longitude": "27.1350"
        },
        "timezone": {
          "offset": "+5:45",
          "description": "Kathmandu"
        }
      },
      "email": "ceyhan.dizdar@example.com",
      "login": {
        "uuid": "34eb65b2-0535-4656-bd68-4da69dc6d016",
        "username": "orangefish864",
        "password": "grandpa",
        "salt": "vowzvAS2",
        "md5": "cf4a7f3210ef97e8e72defafd80b94c8",
        "sha1": "4f2af3439862b9bf25757ee73df8cd410ce201a2",
        "sha256": 
        "1497acbca446b5fa47d4bc5ffe4e82c17818176596b66d94f213f091c8ed8077"
      },
      "dob": {
        "date": "1979-08-10T22:03:55Z",
        "age": 39
      },
      "registered": {
        "date": "2008-05-24T13:30:20Z",
        "age": 10
      },
      "phone": "(873)-801-4132",
      "cell": "(751)-606-5317",
      "id": {
        "name": "",
        "value": null
      },
      "picture": {
        "large": "https://randomuser.me/api/portraits/women/59.jpg",
        "medium": "https://randomuser.me/api/portraits/med/women/59.jpg",
        "thumbnail": 
        "https://randomuser.me/api/portraits/thumb/women/59.jpg"
      },
      "nat": "TR"
    }
  ],
  "info": {
    "seed": "008a9fe3a638239b",
    "results": 1,
    "page": 1,
    "version": "1.2"
  }
}

Now the question is this: write an arrow function example displayBirthdate(), pass in this object(extra) as a parameter. using de-structuring method, grab the "dob" property in the object(extra). below is how i have attempted to solve the question:

const displayBirthdate = (obj) =>{
        const{results} = obj;
        const[{dob}] = results;
      }

but it appears to be incorrect. please any help would be appreciated. thank you

Devjoseph
  • 61
  • 1
  • 4

2 Answers2

0

In your attempted solution, you were trying to obtain the dob object from results, but const{results} = obj; evaluates results to an array. const {dob} = results[0]; in my answer gets the dob object from the first element in the results array. Cheers!

const displayBirthdate = (obj) =>{
    const{results} = obj;
    const[{dob}] = results;
}
const displayBirthdate = (obj) =>{
    const {results} = obj;
    console.log(results); // this is an array with the required object at index = 0
    const {dob} = results[0];
    console.log(dob); // dob is the object you are looking for
}
orimdominic
  • 995
  • 10
  • 23
  • 1
    Hi! While this may be an answer to OP's question, code only answers are discouraged on SO. Adding some context would help OP understand why this answer is sufficient, and it will help future visitor's to the site. Thanks! – d_kennetz Apr 09 '19 at 16:08
  • @d_kennetz You are very right. I was looking at multiple questions so I quickly placed an answer here to move to another answer that's why I couldn't provide an explanation. I've added one now tho – orimdominic Apr 10 '19 at 14:39
0
const displayBirthdate = ({dob}) => {};
const displayAddress ({location}) =>{};