About Destructuring Assignment to Assign Variables from Objects

i have a feeling that I don’t understand the full picture of this tutorial, i have no idea what to do.
it’s giving me this :
“destructuring with reassignment was used”

Your code so far


const AVG_TEMPERATURES = {
  today: 77,
  tomorrow: 79
};

function getTempOfTmrw(x) {
  "use strict";
  
  const  {tomorrow: tempOfTomorrow} = x; 
  
  return tempOfTomorrow;
}

console.log(getTempOfTmrw(AVG_TEMPERATURES));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.

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

I think you solved the problem correctly but by changing the name of the argument to ‘x’ you messed up their test. The instructions were to not change code above a certain line which you have done.

1 Like

Is it just being finicky because you changed the name of the argument - avgTemperatures is the one used in the code, and you’ve changed it to x. It looks correct otherwise, I don’t think you’re misunderstanding anything

Edit: Snap!

1 Like

Weird thing, but this challenge doesn’t work with the right code.

const AVG_TEMPERATURES = {
  today: 77.5,
  tomorrow: 79
};

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

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

This code doesn’t work. With “today : a” or without - an error occurs. “destructuring with reassignment was used”
I think there is something wrong with this challenge.

1 Like

Your issue is here:

const {tomorrow : tempOfTomorrow, today : a} = AVG_TEMPERATURES

You are accessing the test object directly, not the object being passed into the function

1 Like

oh, thank you. I got task a bit wrong.

thank you for the help guys, i think this tutorial was the most difficult one I encountered so far!!