ES6 - Destructuring Nested Objects

Tell us what’s happening:
It’s telling me that nested destructuring was not used. What am I doing wrong?

Your code so far


const LOCAL_FORECAST = {
  today: { min: 72, max: 83 },
  tomorrow: { min: 73.3, max: 84.6 }
};

function getMaxOfTmrw(forecast) {
  "use strict";
  // change code below this line
  const { tomorrow: { max: maxOfTomorrow }} = LOCAL_FORECAST; // change this line
  // change code above this line
  return maxOfTomorrow;
}

console.log(getMaxOfTmrw(LOCAL_FORECAST)); // should be 84.6

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0.

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

1 Like

Hey bro, the problem I think it’s in your function definition, you are not using the parameter forecast instead, you are using the constant you created LOCAL_FORECAST. Chang e that and that should do it. Check this pen if not clear

2 Likes

Thank you :slight_smile: it works

1 Like

It seems to me like the text for this challenge is written incorrectly.

const a = {
start: { x: 5, y: 6},
end: { x: 6, y: -9 }
};
const { start : { x: startX, y: startY }} = a;
console.log(startX, startY); // 5, 6

In the example above, the variable start is assigned the value of a.start, which is also an object.

It refers to the “variable start” being assigned a value. No, start is an object nested within another object “a”. The new variables being assigned values are startX and startY.

This really confused me.