ES6: Use Destructuring Assignment to Assign Variables from Objects problem

Here is my code:

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

function getTempOfTmrw(avgTemperatures) {
  "use strict";
  // change code below this line
  let tempOfTomorrow = undefined;
  const {tomorrow} = avgTemperatures; // change this line
  tempOfTomorrow = tomorrow;
  // change code above this line
  return tempOfTomorrow;
}

console.log(getTempOfTmrw(AVG_TEMPERATURES)); // should be 79

I get error destructuring with reassignment was used.

console.log gives me the correct result: 79.

you need to do it all in one line, and not declare tempOfTomorrow in the previous line (also you don’t need to explicity assign a value of undefined to a variable, as that is the default value)

3 posts were split to a new topic: ES6: Destructuring challenge

destructuring is just a fancy way to assign variables from object values

// const today = avgTemperatures.today
// const tomorrow = avgTemperatures.tomorrow

const {today, tomorrow} = avgTemperatures // does the same thing as above

return tomorrow // output is 79

Object Destructuring - MDN

Thanks, it worked.:grinning: