Tell us what’s happening:
Where am I doing it wrong?
Your code so far
const AVG_TEMPERATURES = {
today: 77.5,
tomorrow: 79
};
function getTempOfTmrw(avgTemperatures) {
"use strict";
// change code below this line
const {tomorrow: tempOfTomorrow} = AVG_TEMPERATURES; // change this line
// change code above this line
return tempOfTomorrow;
}
console.log(getTempOfTmrw(AVG_TEMPERATURES)); // should be 79
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-objects
The function takes an argument, called avgTemperatures
. You haven’t used it, you’re using the object used to test your code instead.
1 Like
Can you be more specific, please? I don’t understand what to do and where to use that argument.
Assume this does not exist:
const AVG_TEMPERATURES = {
today: 77.5,
tomorrow: 79
};
Now how would you make your function work? I get the challenge wording is not fantastic, but the above is just an object used to test the function to see if it works
Look at this again:
That constant is being passed into the function. Imagine, if it was this:
getTmpOfTmrw({
today: 77.5,
tomorrow: 79
})
Then how would you do it?
const {tomorrow: tempOfTomorrow} = AVG_TEMPERATURES;
But I’m still not using the avgTemperatures
parameter and I get this error: destructuring with reassignment was used
Update: I finally understood now. Many thanks.
This was the solution: const {tomorrow: tempOfTomorrow} = avgTemperatures
3 Likes