ES6: Use Destructuring to Assign Variables from Objects

ES6: Use Destructuring to Assign Variables from Objects
0
#1

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.

const AVG_TEMPERATURES = {
  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?

#2

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.

#3

Yeah, that was it. Thank you!

#4

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
#5

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

#6

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