I cannot complete clause: 'destructuring with reassignment was used'

I cannot complete clause: 'destructuring with reassignment was used'
0

#1

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.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-objects


#2
  var {tomorrow} = avgTemperatures;
  const tempOfTomorrow = tomorrow;  // change this line

You don’t need to 2 lines here. You can assign tomorrow to tempOfTomorrow on the same first line.

Try to use this syntax. In deconstruction, you are assigning values from left to right divided by colon.

const { x : a, y : b, z : c } = voxel // a = 3.6, b = 7.4, c = 6.54


#3

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 .


#4

I’m getting the first check but not the second.

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.


#5

can you share you edited code ?


#6

Think of the syntax like the following:

const {objectPropertyName: newVariableName } = objectName;

#7

This is what I have. I think it’s right but if it’s not it might be close enough to give the answer away so I blurred it.

const { tomorrow : tempOfTomorrow } = AVG_TEMPERATURES;

With just that one line between the change code below and above this line comments I can’t get the second check.

My output is
// running tests
destructuring with reassignment was used
// tests completed


#8

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


#9

You’re almost there. The syntax is for destructuring is correct so…

…you are desctucturing the right way

…but you are destructuring the wrong thing. Should be the object passed into function as parameter…


#10
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

#11

This is the solution I have given:

const { today : tempOfToday ,tomorrow : tempOfTomorrow } = avgTemperatures;

I am getting the output 79. But still getting the “destructuring with reassignment was used” message. Can someone help?


#12

You only need the tomorrow in the destructuring assignment, not today


#13

But doesnt hurt the destructuring does it. Even if I put only tomorrow I am getting the same error. Same for the nested destructuring as well.

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

Same message I am getting for nested destrucuring as well


#14

Not sure of the issue here, I’d need to see your full code


#15

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 : 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”.


#16

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.


#17

Clearing the browser cache actually worked…Thanks Dan :v: