Use Destructuring Assignment to Assign Variables from Objects Moose

Tell us what’s happening:
I simply do not understand how to do this problem. I don’t really understand what it’s asking me to do. Any help would be appreciated. Sorry for not being more specific but I just need a better explanation of what I’m supposed to do/how I’m supposed to apply what’s in the lesson to the problem. I’m supposed to take the tomorrow key value (79) of the first object and set it the second’s tomorrow key value.

Your code so far


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

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

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

Yeah, this stuff is weird when you start learning it.

Consider the following:

const dog = { age: 5 };
console.log('dog.age', dog.age);
// dog.age 5

const { age } = dog;
console.log('age', age);
// age 5

const { age: myDogsAge } = dog;
console.log('myDogsAge', myDogsAge);
// myDogsAge 5

First we create an object.

Second, we destructure the age property out and assign it to a new variable with the same name. Note that these are two different variables. They start out the same but because these are a primitive type (in this case, a number) changing one will not change the other.

In the third case, we want to pull out that property but we don’t want it to be called age, we want it to be in a new variable called myDogsAge.

This is similar to the challenge. Inside the function you are passed the object avgTemperatures. You want to destructure the property tomorrow out of it but want it to be called tempOfTomorrow instead.

Yes, it is worded confusingly. You are not the first to be confused by this challenge. Even if it were worded perfectly, it is a weird looking syntax until you get it.

Let us know if you need more help.