(SOLVED)Use-destructuring-assignment-to-assign-variables-from-nested-objects

Tell us what’s happening:
After using the exact same syntax as what is seen in the freecodecamp video on youtube and the example given in the lesson I still cannot seem to pass the “nested destructuring used” test

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/65.0.3325.181 Safari/537.36.

Link to the challenge:

1 Like

You’re not crazy. It works for me, and outputs 84.6 to my browser console. I’ve noticed that when stuff like this happens, it’s really helpful to hit the “reset your code” button. Just select and copy the line you wrote, and paste it in after the code has been reset.

2 Likes

So I figured out the issue with this code. Instead of using the parameter fed into the function I was using the Global Variable Declaration.

Meaning that this line:
const { tomorrow : { max: maxOfTomorrow }} = LOCAL_FORECAST;

Should have been this:
const { tomorrow : { max: maxOfTomorrow }} = forecast;

Darn Scope being sassy with me

10 Likes

Goddamn scope. I have no idea why it worked in the pen. Now I’m scared.

1 Like

nice catch, had the same solution/problem as you.

Not that our solution was necessarily “wrong” in this case, just not the best…the failed test message was confusing in this case.

I don’t understand why const { tomorrow : { max: maxOfTomorrow }} = LOCAL_FORECAST;
can’t work???
Can anyone explain it to me? Thanks in advance!

because in a function the parameter should be bettween brackets and then inside the code we put also that parameter wich works as local variable in the function and finally when we want to call the function we input the argument of that parameter we define it .
in this challenge the parameter is forcaste so inside the code we should put also forcaste and when we want to call the function we define the parameter by LOCAL_FORECAST wich is actually the name of an object .
in bref this is like we are writing a variable like this var forcaste= LOCAL_FORECAST
I hope this helps slight_smile:

I think I got it. Many thanks!!

thanks , i was going crazy

Hi there , My code is same but my second test case : “nested destructuring was used” doesn t pass

You might have used this statement
const { tomorrow : { min: minOfTomorrow , max : maxOfTomorrow } } = forecast;
which is perfectly fine as it returns the correct temperature.

Instead replace it by const { tomorrow : { max: maxOfTomorrow }} = forecast; this statement. Well this worked for me no reason but both of them are correct in general. But to pass that test you have to use the second statement.

GOOD JOB bro
the challenge deals with parameter to pass the object.

So at no point is the original variable LOCAL_FORECAST referenced to. That makes a lot of sense… Jeees I hate this ES6 module!!!