Doubt in code: Use Destructuring Assignment to Pass an Object as a Function's Parameters

Tell us what’s happening:
I’ve passed the situation with my code that is down below, but then I’ve changed it to the new values that I’ve assigned to each variable inside the Object and provides me with NaN.

I don’t understand why.

So I think I’ve passed with a bit of luck perhaps, because this seems way odd for me to understand why it didn’t worked out.

Attached I’ve got two print screens of the situation.

  **Your code so far**
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 {max : maxValue, min: minValue} = stats;

const half = ({ max, min }) => {
return (max + min)/2.0
}

// Only change code above this line

console.log(half(stats))


  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36

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

Link to the challenge:

In the screenshot you provided above, you attempted to destructure two properties (maxValue and minValue) from stats, but those properties do not exist. The half function ends up returning NaN because (undefined + undefined) / 2.0 is equal to NaN. The two undefined values are the result of you destructuring properties that do not exist.

FYI: The following line from both of the code sections you show are doing nothing for you as the half function is using the destructured parameter and not the global variables outside the function.

const {max : maxValue, min: minValue} = stats;
1 Like

Thanks for the reply RandellDawson

Now I understand better what I did :+1:

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