Use Destructuring Assignment to Assign Variables from Objects - Help!

Tell us what’s happening:
Why my code doesn’t work?I can’t pass the “destructuring with reassignment was used”??
Can somebody help?

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.2 Safari/605.1.15.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-objects

In a real world case, you would never see that global AVG_TEMPERATURES. Your function should almost never be aware of any variables outside of itself.

But… Your function is getting a parameter. Can you see a way to use THAT, instead?

Side note, most of the questions you’ll be asking on the forum have already been asked and answered. I field this one maybe once a week. Word of advice? Search the forums.

1 Like

I see that you’re using “:” into your braquet. In this way, it just look like you’re trying to set a object with the “tomorrow” property and tempOfTomorrow ( undefined ) as value.

const { tomorrow } = AVG_TEMPERATURES
return tomorrow

It should workd like that.

Well, yes and no @NastYo – take a look at the code. The return tempOfTomorrow is something that is set in the provided code, you need to create a variable with that name. The format used is accurate, it says “get tomorrow AS tempOfTomorrow FROM avgTemperatures”.

Bear in mind, the only part of the function you’re allowed to alter is between the

// change code below this line

and

// change code above this line

Yea you’re right. Then in this case, I don’t realy understand why should he use the destructuring assignment. My first answere pointing on how to use destructuring.

But as you mentioned, it’s not what he need. Just set a new variable with the data(average), then hiswork and return this new variable.

Note also that here you are using the global variable when you should be using the function parameter - even with this you don’t pass the “destructuring assignment was used” test

1 Like