I can’t validate this exercice on beta;freecodecamp :
This is my code :
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 code above this line
return maxOfTomorrow;
}
console.log(getMaxOfTmrw(LOCAL_FORECAST)); // should be 84.6
maxOfTomorrow get the right value “84.6” but I still get the error message saying I’m not using nested destructuring :
V “maxOfTomorrow equals 84.6”
X “nested destructuring was used”
I used nested destructuring I did like in example, so where is the problem ?
forecast is the variable passed to the function that the assignment asks you to write. In your intitial code you used the global variable instead of the passed through parameter. In this case it worked out fine but it’s not best practice and would not have worked if LOCAL_FORECAST was defined locally within another function.
Whether or not FCC should fail this particular exercise for using LOCAL_FORECAST is another discussion…
I also spent quite some time around this issue as well, and even worse, I was already using forecast. My problem was that I was destructuring the whole tomorrow object so I was failing the “nested destructuring was used” criteria. This seems weird to me and the last two ES6 exercises are leaving me with the feeling that these new challenges were somehow rushed.
Here is the code that was failing me:
const {tomorrow: {min: minOfTomorrow, max: maxOfTomorrow}} = forecast;
This is the correct one…
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