About Destructuring Assignment to Assign Variables from Objects

About Destructuring Assignment to Assign Variables from Objects
0

#1

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


#2

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.


#3

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!


#4

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.


#5

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


#6

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


#7

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