Use Destructuring Assignment to Assign Variables from Nested Objects - recurring error

Use Destructuring Assignment to Assign Variables from Nested Objects - recurring error
0.0 0

#1

Tell us what’s happening:
I am not really sure what is happening, on the console, it wrote:
maxOfTomorrow equals 84.6
nested destructuring was used

but in the tests check, both failed.

This recurred for the previous test also.

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: {min, maxOfTomorrow}} = forecast; // change this line
 // const maxOfTomorrow = max;
  // 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


#2

The text that appears in the console are just the tests which failed. So, you failed the test which checks if maxOfTomorrow equals 84.6 and you failed the test that checks that nested destructuring was used.

It is a little confusing and I believe they are working on changing how this information gets display to avoid the confusion.


#3

You’ll need to store the value of max into maxOfTomorrow


#4

Thanks for the help @randelldawson and @mjbenefiel

So I replaced the line with this:

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

and still got this on the console:

nested destructuring was used

this error is what is bothering me the most because I don’t really know what is causing it.


#5

console log shows 84.6, so I’m not 100% sure why that solution won’t pass. I know some of these ES6 challenges have bugs.

I try to read these challenges in their most literal sense, and did not include min the first time I passed the challenge. Sorry I couldn’t go more in depth here, but maybe I saved you some frustration that some of these newer challenges pose.


#6

The challenge test is looking for the minimum code to solve the problem. You do not need to include the min property, because it is not relevant to solve this challenge. Technically, your code is correct and will assign 84.6 to maxOfTomorrow, but the test is not expecting to see the extra code. Could the test be written to allow the min property? Probably. You can open a new Issue on gitbhub if one is not already been opened.


#8

Thanks!

That strict requirement is confusing for someone who is still learning the ropes to this.