Why adding {} is wrong here

Tell us what’s happening:
without {} this code works fine. Otherwise it shows [ half (stats) should be 28.015]Why?
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 }) =>{ (max + min)/ 2.0};
//const half = ({ max, min }) => (max + min) / 2.0;
// Only change code above this line
  **Your browser information:**

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

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

Link to the challenge:

Which {} do you mean?

You forgot the return statement in your code, it’s necessary when you use { } to wrap your function! in this case it’s an expression so you can write it in one line without { }

const half = ({ max, min }) =>{ return (max + min)/ 2.0 }; 
// will work, you are returning a value generated by an a expression in a block of code

const half = ({ max, min }) =>{ (max + min)/ 2.0}; 
// function is returning 'undefined' which means that the execution has finished because you don't specify what to return, but undefined != 28.015 !

const half = ({ max, min }) => (max + min)/ 2.0 ; 
// if you don't use {} on inline functions the return statement is implicit, but ONLY on inline functions with expressions. This will return a value.
2 Likes

thank you @chaloxc
I got it now! :smile:

Here I meant “{ (max + min)/ 2.0}”. BTW I got the answer. :smiley: Thank you for your support :innocent: