Tell us what’s happening:
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};
// Only change code above this line
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
.
Challenge: Use Destructuring Assignment to Pass an Object as a Function’s Parameters
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
ilenia
December 28, 2020, 7:25am
#2
Hello there.
Do you have a question?
If so, please edit your post to include it in the Tell us what’s happening section.
The more information you give us, the more likely we are to be able to help.
Hi @Chirashankar6 !
Welcome to the forum!
Two issues.
First, you don’t need the curly braces here
Chirashankar6:
{max + min / 2.0};
Secondly, you deleted parenthesis from the original code.
Original
(stats.max + stats.min) / 2.0;
Removing the stats was correct but removing the parenthesis is incorrect.
Remember PEMDAS (Parentheses, Exponents, Multiplication/Division, Addition/Subtraction)
When you have the parenthesis, max + min will be executed first then that answer will be divided by 2.
With your current code, min/2 will be executed first then that result will be added to max.
Hope that makes sense.
Chirashankar6:
happening
I am unable to pass " half(stats)
should be 28.015
" this part of the assignment
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};
// Only change code above this line
ilenia
December 28, 2020, 10:12am
#7
your function does not return a value*, and you are still missing the parenthesis and your function is calculating max + (min / 2)
because of operation precedence
* arrow functions have implicit return or explicit return
x => x+2 // implicit return
x => {return x + 2} // explicit return, if you use {} around the function body you must use return keyword
Thank you @ieahleen ,I corrected it.