Use Destructuring Assignment to Assign Variables from Nested )Objects

Use Destructuring Assignment to Assign Variables from Nested )Objects
0

#1

Tell us what’s happening:
Omg where is the problem?

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.99 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


#2

Instead of using the const LOCAL_FORECAST, remember to use the parameter that’s passed inside the function.


#3

It tell that:
nested destructuring was used


#4

Can you paste your code after you re-tried?


#5

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

I have that code! :grinning:


#6

Yes, so read my first reply carefully. Don’t assign the constant that’s defined on top. But use the parameter that’s passed in for you.

If you are still having trouble

const { tomorrow : { max : maxOfTomorrow}} = forecast; // change this line


#7

Thank you I passed the test.Thank you for helping.


#8

You welcome. Please mark my reply as solution so indicate your question was resolved. :slight_smile:


#9

Thanks for asking the question and thank the one who answered it correctly.