Need help with "ES6: Use Destructuring Assignment to Pass an Object as a Function's Parameters"

Tell us what’s happening:
I’m having trouble to understand how it works.

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 half = () => (max + min) / 2.0; 
// Only change code above this line

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0.

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

Link to the challenge:

you should change code like below.

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

let me explain.
“const stats” is an independent object with function “const half”.
the function half is an arrow function which takes two parameters to get average value of two inputs. don’t pass stats value as a parameter. it’s independent function. it can take any parameter.
hope it 'll help you.

1 Like

Thanks, now I understand.
I remember that it’s a function now, forgot that you had to add max and min as parameters, will try to remember for next time.

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.
If you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

1 Like