ES6: Use Destructuring to Assign Variables from Objects

ES6: Use Destructuring to Assign Variables from Objects

I searched around for what other people posted about this challenge, but their challenges look different. Did FreeCodeCamp update it recently? Anyhow, here’s what I came up with.

  today: 77.5,
  tomorrow: 79

function getTempOfTmrw(avgTemperatures) {
  "use strict";
  // change code below this line
  const { today : whatever, tomorrow : tempOfTomorrow } = avgTemperatures; // change this line
  // change code above this line
  return tempOfTomorrow;

console.log(getTempOfTmrw(AVG_TEMPERATURES)); // should be 79

My function returns 79 as it should, but I’m failing the ‘destructuring with reassignment was used’ test. I’m pretty positive that’s what I used, though. Is there a bug in the challenge, or do I have some kind of blind spot?


It appears at a glance that you did the destructuring of the object properly but you destructured both properties when you only needed the one.


Yeah, that was it. Thank you!


This is an old thread but it was the first results when I searched the same name. You can fail for the same reason if you use
const { tomorrow : tempOfTomorrow } = AVG_TEMPERATURES;
instead of
const { tomorrow : tempOfTomorrow } = avgTemperatures;
Took me a while to notice that one.

1 Like

Thanks, you’re right. Doesn’t make sense though!


well, the tests can’t know if you used destructuring without checking what you wrote, so there are some limitations to solve this challenge