Need help Use Destructuring Assignment to Assign Variables from Objects

Tell us what’s happening:

Your code so far


const AVG_TEMPERATURES = {
  today: {low : 70, high: 77.5 },
  tomorrow: {low : 78.3, high :79}
};

function getTempOfTmrw(avgTemperatures) {
  "use strict";
  // change code below this line
  const {tomorrow : {high : 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_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 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 have also tried

const AVG_TEMPERATURES = {
today: {low : 70, high: 77.5 },
tomorrow: {low : 78.3, high :79}
};

function getTempOfTmrw(avgTemperatures) {
“use strict”;
// change code below this line
const tempOfTomorrow = AVG_TEMPERATURES.tomorrow;// change this line
// change code above this line
return tempOfTomorrow;
}

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

It appears that this challenge has changed some since you have started working on it. I just visited the page and the AVG_TEMPERATURES object is a bit simpler than in your code shown above. So the new solution no longer requires a complex nested destructuring.

I believe that you are doing the destructuring assignment correctly but you are destructuring the wrong thing.

The function accepts one argument locally named avgTemperatures. That is what you should be destructuring, not the global object AVG_TEMPERATURES. That way you could call the function on any temperature object, not just that particular one.

const AVG_TEMPERATURES_ALASKA = {
  today: {low : 27, high: 36 },
  tomorrow: {low : 32, high :40}
};

// this would not work the way you are doing it
console.log(getTempOfTmrw(AVG_TEMPERATURES_ALASKA)); // sb 40 but would get 79 for any argument

I still do not get it

Make sure to use the argument avgTemperatures instead of the constant AVG_TEMPERATURES .

Also, you may have to reset your challenge code because it seems they’ve changed the AVG_TEMPERATURES constant - it is easier.

I just started from scratch and figured it out. I had to use avgTemperatures and it worked. Thanks everyone