Use Assign Variables from Objects

Tell us what’s happening:

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 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 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

You’re trying to assign the variable using the const AVG_TEMPERATURES from outside of your function. Your function does not have access to this const. You need to use the const that is within / passed to your function instead which is avgTemperatures.

@MrPrew is right that you must use avgTemperatures instead of AVG_TEMPERATURES. I just want to add that your function do have access to AVG_TEMPERATURES because of how scope works. Also avgTemperatures is actually an argument, thus it is variable, and not const.

Still, FCC tests checks that you’re actually using the argument avgTemperatures instead of the const AVG_TEMPERATURES.

1 Like