Destructuring with reassignment was used. Please help with this error

Destructuring with reassignment was used. Please help with this error
0

#1

Question: Use destructuring to obtain the average temperature for tomorrow from the input object AVG_TEMPERATURES , and assign value with key tomorrow to tempOfTomorrow in line.

Error : “destructuring with reassignment was used remains” remains unticked.

Initial code:

const AVG_TEMPERATURES = {
today: 77.5,
tomorrow: 79
};

function getTempOfTmrw(avgTemperatures) {
“use strict”;
// change code below this line
const tempOfTomorrow = undefined; // change this line
// change code above this line
return tempOfTomorrow;
}

console.log(getTempOfTmrw(AVG_TEMPERATURES)); // should be 79

Your code so far


const AVG_TEMPERATURES = {
  today: 77.5,
  tomorrow: 79
};

function getTempOfTmrw(avgTemperatures) {
  "use strict";
  // change code below this line
  const {today:tempOfToday, tomorrow:tempOfTomorrow} = AVG_TEMPERATURES;
   // 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 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 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

Use the parameter avgTemperatures inside the function instead of the constant AVG_TEMPERATURES.


#3

Ghukahr, thank you for your help. I’ve tried doing so; however, the problem persists.I’m still getting the same error. My updated code is below:

const AVG_TEMPERATURES = {
today: 77.5,
tomorrow: 79
};

function getTempOfTmrw(avgTemperatures) {
“use strict”;
// change code below this line
const {today:tempOfToday, tomorrow:tempOfTomorrow} = avgTemperatures;
// change this line
// change code above this line
return tempOfTomorrow;
}

console.log(getTempOfTmrw(AVG_TEMPERATURES)); // should be 79


#4

It looks like the test wants you to destruct only the tempOfTomorrow. No need to get the tempOfToday too. It shouldn’t matter, but sometimes FCC tests are a little too rigid.


#5

I hear what you’re saying and have adjusted the code accordingly; however, the problem persists. My updated code is below:

const AVG_TEMPERATURES = {
today: 77.5,
tomorrow: 79
};

function getTempOfTmrw(AVG_TEMPERATURES) {
“use strict”;
// change code below this line
const {today, tomorrow:tempOfTomorrow} = AVG_TEMPERATURES;
// change this line
// change code above this line
return tempOfTomorrow;
}

console.log(getTempOfTmrw(AVG_TEMPERATURES)); // should be 79


#6
  1. FCC tests doesn’t want that today there :smiley:
  2. Why did you changed the parameter name?

#7

I guess I misread the question. Either way, I still get the same error.

const AVG_TEMPERATURES = {
today: 77.5,
tomorrow: 79
};

function getTempOfTmrw(AVG_TEMPERATURES) {
“use strict”;
// change code below this line
const {tomorrow:tempOfTomorrow} = AVG_TEMPERATURES;
// change this line
// change code above this line
return tempOfTomorrow;
}

console.log(getTempOfTmrw(AVG_TEMPERATURES)); // should be 79


#8

The name of the parameter should be avgTemperatures and not AVG_TEMPERATURES.

Its unfortunately but all of this shouldn’t matter at all since you’re returning the correct value. It is just that FCC tests are being too strict.


#9

I also think so. I’ve tried changing the parameter name to avgTemperatures but I’m still faced with the same error. Did you get passed this challenge?


#10

Are you sure you changed it correctly?

This passes for me:

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

:smiley: I see. The parameter and the variable name should have been identical. My parameter was avgTemperatures but the constant it referred to was AVG_TEMPERATURES.
It now works. Thank you for your help and patience, Ghukahr.