Use Destructuring Assignment to Assign Variables from Objects - destructuring with reassignment was used

I’ve been stuck on this challenge about one hour :frowning: someone could explain it for me???

Your code so far


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

function getTempOfTmrw(avgTemperatures) {
  "use strict";
  // change code below this line
  const tempOfTomorrow = AVG_TEMPERATURES.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 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36 OPR/55.0.2994.47.

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

2 Likes

You are passed the argument variable avgTemperatures, but you are not using it anywhere in your code. You are also not using destructuring.

2 Likes

Hey ya,

You should be using destructuring:

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

Here you are saying that you want a const called tempOfTomorrow that has the same value of avgTemperatures.tomorrow

Got it?

4 Likes

You are using destructuring to capture both today and tomorrow properties’ values:

const {tomorrow: tempOfTomorrow,  today: tempOfToday} 

but the instructions and tests are expecting you to only capture tomorrow’s value and assign it to tempOfTomorrow.

const {tomorrow: tempOfTomorrow}

You’re using the object used to test the function inside the function. The function takes an argument (avgTemperatures), and you can test it using the provided object AVG_TEMPERATURES

const {tomorrow: tempOfTomorrow} = avgTemperatures;
9 Likes

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.

2 Likes

Ma mistake :frowning:

Thank you for the feedback

Thank you very much!
Your comment helped me a lot.

1 Like

I was stuck for a few hours. The example code and the challenge code does not match. It is still confusing to me, even though they had fixed it from the initial challenge. Look it up on GitHub.

2 Likes

Thank you for your help. I was struggling as well for the destructure.
I thought it should be
const {tomorrow: tempOfTomorrow} = AVG_TEMPERATURES;

Hello World! (ie: first post here)

I lost a few extra minutes on this challenge too.
I think this should be an example for bad naming practices and the problems they cause :slight_smile:

Yes you can get the correct assignment by using the globally declared object, yet the challenge wants you to solve it through the argument passed to the function.

1 Like