Use Destructuring Assignment to Assign Variables from Objects677

Tell us what’s happening:
i am not able to pass my second criteria

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 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/73.0.3683.86 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/

Actually, the answer to this question is all over these forums. If you were to search here for “destructuring assignment”, for example, you might find that this is almost a weekly thing (if not more often).

So you are writing a function, and that function is receiving a parameter, named avgTemperatures. What that variable looks like, we know from above, when AVG_TEMPERATURES is assigned, but we aren’t being passed AVG_TEMPERATURES, we’re being passed a local variable named avgTemperatures. The issue here is, you’re referencing a global variable rather than the local one. In production code, you can’t really trust globals – some other function may change them, or they simply may not exist. In the context of your function, though, you know you have an avgTemperatures local variable, you are defining it.

If you rewrite your code to use the local variable, rather than the global one, you should be fine.

2 Likes