Use Destructuring Assignment to Assign Variables from Nested Objects -- help me

I don’t understand where I’m wrong.
it doesn’t pass the “nested destructuring was used” objective

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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36.

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

You are destructuring the LOCAL_FORECAST variable instead of the forecast argument.
Correct implementation below

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

If you not use the LOCAL_FORECAST, the function only works for that specific forecast. When you use the forecast argument, your function is reusable for every forecast that is passed to it as argument.

2 Likes

thank both of you, what a silly oversight

1 Like