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

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

I HAVE A DOUBT THAT WHILE SOLVING DESTRUCTRING PROBLEM WHY IT IS ASIGNING TO FORECAST INSTEAD OF THE FIRST CONST LIVE_FORECAST

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}} = forecast; // change this line
  // change code above this line
  return maxOfTomorrow;
}

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

Hi @talhaspartan!

It seems the problem is “use strict” in FCC. If you remove it you’ll pass the exercise (I tried myself).

1 Like

Your code passes for me.

1 Like

the code is compiling but i want to know why we are using forecast …there

NO , its not passing in free code camp its showing error in console like
“nested destructuring was used” i want to know why
(when i am changing forecast to LOCAL_FORECAST )
AND I REMOVED THE USE STRICT ALSO

You are using forecast because that is the object passed to the function for you to destructure.

1 Like

ya thanx, i got that but what is happening when i am using LOCAL_FORECAST

The test is not wanting you to use it.

1 Like

Well, it looks like it doesn’t want nested destructuring. It probably wants this:

const {max: maxOfTomorrow} = forecast.tomorrow;

But, it’s weird you’re getting that error because it says it wants it to be nested destructuring.
Also, your code passes for me. Are you using Chrome?

1 Like

forecast is the function parameter, and you use that to make your function reusable. LOCAL_FORECAST is a global object, which is passed in the function as argument in the function call at the bottom of the code

1 Like

YES i am using crome but when i am using .tomorrow at the end its saying error

Well, that’s strange that the test doesn’t pass with your code. It’s not supposed to pass with mine actually.

1 Like

Can you please post your latest code? You should not be using forecast.tomorrow.

1 Like

The one in the top posts passes for me, I think it’s the latest.

If it doesn’t pass, then what version of Chrome are you using? If it’s old (like 55 or something) try updating it.

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}} = forecast; // change this line
// change code above this line
return maxOfTomorrow;
}

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

that should work, I don’t know why it doesn’t

1 Like

Can you share with us what browser and what version you are using? Also, can you post a screen shot of what the FCC console shows when you click Run Tests?

1 Like

i am using CROME browser
and this is my code (currently working )
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}} = forecast; // i have a problem in understanding this line (why forecast and why not LOCAL_FORECAST
// change code above this line
return maxOfTomorrow;
}

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

and in console i am getting correct value .
i just want to know that when i am changing forecast to LOCAL_FORECAST whats happening in that line ehere i am using nested destructring …

Oh, so it’s solved, right?