Using Destructing assignment to pass an object as an function Parameter

const stats = {
  max: 56.78,
  standard_deviation: 4.34,
  median: 34.54,
  mode: 23.87,
  min: -0.75,
  average: 35.85
};

// change code below this line
const half = ({max,min}) => (max + min) / 2.0; 
const halfk = function ({max,min}){
  (max + min)/2.0;
}
// use function argument destructuring
// change code above this line

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

Can you please tell me why my last console.log statement gives Undefined??

Hi!

You are missing the return statement on this line

 (max + min)/2.0;

I added this

var result = (max + min) /2.0;
  return result;

It’s working fine. Thanks

1 Like