Use Destructuring Assignment to Assign Variables from Objects 4

Tell us what’s happening:

The assignment still has an X next to destructuring with reassignment was used and I can’t see what I’m doing wrong.

Your code so far


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

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

Nevermind, I figured it out

This assignment is invalid. Your variable tempOfTomorrow is not assingn the value of tomorrow key.

This must works: const {tomorrow} = AVG_TEMPERATURES;

Remember returns tomorrow.

Thanks, but it was actually because I was using the global variable AVG_TEMPERATURES instead of the argument avgTemperatures

1 Like

That is the global variable, you need to use the parameter of the function, avgTemperatures, so that the function can be reused

True true. @Jeffreyb723 @ilenia . I forgot the flexibility of the destructuring. Therefore, it must be made a habit.