Use Destructuring Assignment to Pass an Object as a Function& Parameters

Use Destructuring Assignment to Pass an Object as a Function& Parameters
0

#1

Tell us what’s happening:
Hi guys,this code works just fine but the thing is when i write it in VS it sends me a message that All destructured elements are unused.though the result is correct.Can anyone tell me what’s wrong with my code ?

Your code so far


  "use strict";
const stats = {
  max: 56.78,
  standard_deviation: 4.34,
  median: 34.54,
  mode: 23.87,
  min: -0.75,
  average: 35.85
};
const half = ({max,min}) =>{
  
    return (stats.max + stats.min) / 2.0;
  };
 
  
  


console.log(stats); // should be object
console.log(half(stats)); // should be 28.015

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-pass-an-object-as-a-functions-parameters/


#2

You have completely changed the code in this challenge. You should not be modifying/deleting anything above the line:

// change code below this line

OR below the line:

// change code above this line

You ONLY should be changing the function shown below and using destructuring for the function’s parameters so that you can reference those parameters in the return statement. In your return statement, you are referencing the global variable stats which you should not be doing.

  return function half(stats) {
    // use function argument destructuring
    return (stats.max + stats.min) / 2.0;
  };

Your VS editor is telling you the truth. You used destructuring, but you never used the variables created from the destructuring in your solution.

I suggest you Reset the challenge code and only change the parts where specified.


#3

i only did it because though i could solve the challenge,i never did understand this part :
const half = (function() {
“use strict”; // do not change this line

// change code below this line
return function half(stats) {
// use function argument destructuring
return (stats.max + stats.min) / 2.0;
};
// change code above this line

})();

note:anyone can understand what this code aims to do,i just don’t understand the syntax of so many functions and ()s


#4

You were not supposed to worry about the part outside of the inner function. That was for the tests behind the scenes. You will learn more about that other syntax later in the curriculum. For now, see if you can solve the challenge by only changing the inner function’s code.


#5

well it was pretty easy solving the challenge as asked,i just tried very hard to understand the whole syntax .Didn’t know i wasn’t supposed to understand it at this level.Thanx