Tell us what’s happening:
I clearly don’t get the destructured parameters.
I tried putting min and max as parameters ({min,max}) but it said min was not defined.
Then I tried changing only the function parameters, leaving the whole ‘stats’ when calling the half function. Then it at least gave a result.
BUT, my answer is 28.765 not 28.015, because min is -0.75.
56.78 - (-0.75) = 57.53
Divide that by 2 and it is 28.765. (i.e. (56.78+0.75) / 2)
But below the RUN TESTS, ETC, it says:-
half(stats)
should be 28.015
(which is (56.78-0.75) / 2)
When I RUN TESTS again, it still says:-
half(stats) should be 28.015
Destructuring should be used.
What gives?
Your code so far
// AT FIRST I HAD:-
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
function half(stat) {
const {min:hmin,max:hmax} = stat;
const hcut = (hmax - hmin) / 2.0;
return hcut;
};
const halfCut = half (stats);
console.log("hcut",halfCut);
console.log("half",half(stats));
// Only change code above this line
// THEN I TRIED:-
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
function half({min,max}) {
return (max - min) / 2.0;
};
const halfCut = half (stats);
console.log("hcut",halfCut);
console.log("half",half(stats));
// Only change code above this line
IT GIVES THE SAME RESULT IN console.log (28.765)
**Your browser information:**
I am using Edge in Win10.
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36 Edg/93.0.961.52
Challenge: Use Destructuring Assignment to Pass an Object as a Function’s Parameters
Link to the challenge: