Tell us what’s happening:
Hello, I stuck on this task, please help in what Am I wrong?
I can not complete clause: ‘destructuring with reassignment was used’
Your code so far
const AVG_TEMPERATURES = {
today: 77.5,
tomorrow: 79
};
function getTempOfTmrw(avgTemperatures) {
"use strict";
// change code below this line
var {tomorrow} = avgTemperatures;
const tempOfTomorrow = tomorrow; // change this line
// change code above this line
return tempOfTomorrow;
}
console.log(getTempOfTmrw(AVG_TEMPERATURES)); // should be 79
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.
you should destructure and reassign the variable in the same line think of it as if you are renaming the destructured variable and do as the mentioned examples .
I can get the right output on this one with the code on one line using the syntax shimphillip posted ( const { x : a } = voxel ) but I can’t get the check for destructuring with reassignment was used.
This problem has already been solved : ES6: Use Destructuring Assignment to Assign Variables from Objects SEPT18
You are using directly the name of your tested object (AVG_TEMPERATURES) within your function, which make it contingent. You should put the name of your argument instead (avgTemperatures) so your function can be used with several “temperature” objects that have a tomorrow value.
const AVG_TEMPERATURES = {
today: 77.5,
tomorrow: 79
};
function getTempOfTmrw(avgTemperatures) {
"use strict";
// change code below this line
const {tomorrow : tempOfTomorrow} = avgTemperatures; // change this line
// change code above this line
return tempOfTomorrow;
}
console.log(getTempOfTmrw(AVG_TEMPERATURES)); // should be 79
function getMaxOfTmrw(forecast) {
“use strict”;
// change code below this line
const { tomorrow : { min : minOfTomorrow, max : maxOfTomorrow}} = forecast ; // change this line
// change code above this line
return maxOfTomorrow;
}
console.log(getMaxOfTmrw(LOCAL_FORECAST)); // should be 84.6
The output is 84.6…I am getting it…Along with the message “nested destructuring was used”.
Remove the minOfTomorrow - the tests actually check the code written, not just the output, and including it causes the tests to fail. There is nothing incorrect w/r/t to your code, but the tests are finicky. Once removed, the test passes - try clearing your browser cache and resubmitting the test if it doesn’t work straightaway.
This is the solution.
Inoder to access the value of a property in an object using the destructuring assignment, you can use this syntax.
const {property name: variable name} = object name or the parameter passed in the function;
So, this is my code to the solution:
function getTempOfTmrw(avgTemperatures) {
“use strict”;
// change code below this line
const {tomorrow:tempOfTomorrow} = avgTemperatures; // change this line
// change code above this line
return tempOfTomorrow;
}
console.log(getTempOfTmrw(AVG_TEMPERATURES)); // should be 79
See the function argument properly. Assign the passed argument not the actual object.
AVG_TEMPERATURES is object.
avgTemperatures is argument of function.
Almost 6 months ago I know but I’m with you, the error should be something in the lines of “too many variables assigned” just because the deconstructing was correctly implemented. In the examples there were no mentions if you need to assign all the variables or just one, and including an extra variable seems natural, specially if you’re copying the given example.