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:

The answer is correct but I don’t know why It is not passing the 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 { max: maxOfTomorrow } = LOCAL_FORECAST.tomorrow; // 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 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 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

Hey, this is not correct. You have to

  1. Never refer to specific function argument that specific cases are regarding (LOCAL_FORECAST in this challenge.) Instead referring to the forecast parameter will make the function work for any argument you pass to it.

  2. The challenge is asking you to do nested destructuring, think of it as accessing an object within an object, like this.

{tomorrow :{max:maxOfTomorrow}}

So here’s the full line of code:

const {tomorrow :{max:maxOfTomorrow}} = forecast;


#3

thank you, it is working fine


#4

Good, are you understanding it?


#5

forecast represents any object. And tomorrow is the property of LOCAL_FORECAST object