ERROR: Use Destructuring Assignment to Assign Variables from Objects

Tell us what’s happening:
Failing ‘destructuring with reassignment was used’
Destructuring and reassignment is clearly used

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} = avgTemperatures;
  // 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/

Also, the hint seems to have little or nothing to do with the question.

1 Like

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

Something like this should work.

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Thank you for understanding.

1 Like

Your code is valid. However the test that you are trying to pass is looking for a particular destructuring pattern. The requirements are asking specifically to assign value of tomorrow into tempOfTomorrow. However your pattern desconstructs two values and thus does not meet the required test pattern to pass.

At least this is what I think is going on. It can be frustrating to know something works but you are failing to pass the tests. What I like to do is if my code compiles and my values seem correct. To look at what the requirements are asking and make sure I am fulfilling those.

1 Like