# How do I know if I am picking values from right object?

**How do I know if I am picking values from right object? **
At the end I solved the problem that I had with this part of a course but I have one additional question. Let’s suppose I had two objects that are constants and bouth of them have the same parameters like “max” and “min”. How would I declare from which objects I want values that represent the parameters of a object?

I wanted to by more specific and at first I had done this but I was getting errors:

``````const half = ({max, min} = stats) => (max + min) / 2.0;
``````
``````  **This is the correct solution to the problem**
``````
``````
const stats = {
max: 56.78,
standard_deviation: 4.34,
median: 34.54,
mode: 23.87,
min: -0.75,
average: 35.85
};

// Only change code below this line
const half = ({max, min}) => (max + min) / 2.0;
// Only change code above this line
``````
``````  **Your browser information:**
``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36`

Challenge: Use Destructuring Assignment to Pass an Object as a Function’s Parameters

Link to the challenge:

In the lower left in the test panel of the challenge, you can see that the function `half` is called with the object `stats`:

`half(stats) should be 28.015`

That’s where you specify which object you’d like your function to use. You could call it with a different object:

``````const otherStats = {
max: 100,
min:1
};

half(otherStats)``````

Ou, so when I call function half I just put there some object that has two parameters max and min and that is it? Function will find those arguments in object by itself if I get it right?

1 Like

Almost. You put one parameter into it (some object), which has two properties (max and min). The function will know that it receives one argument, because of your function declaration:

``````// This is the argument being passed in, and you destructure the object right away
// to extract the two properties max and min from it
|
|
V
const half = ({max, min}) => (max + min) / 2.0;
``````

This does exactly the same:

``````const half = (stats) => (stats.max + stats.min) / 2.0;
``````
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.