Use Destructuring Assignment to Assign Variables from Objects Sep 2018

Tell us what’s happening:
I’m stuck in this challange. As far as I know I’ve done what it asks to do. It actually works and the system marks that the expected answer is correct but “destructuring with reassignment was used” is marked wrong, even when I wrote the structure they taught in this lesson. I don’t know what I’m missing.

Your code so far


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

function getTempOfTmrw(tomorrow) {
  "use strict";
  // change code below this line
  
  const {today : tempOfToday, 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 10.0; Win64; x64) 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 should use the argument variable that is passed into your function NOT what you assume its value to be.

1 Like

AVG_TEMPERATURES is an argument of getTempofTmrw() function call.

When working with data inside a function, it’s not the argument to a function call that should be used, but the parameter inserted in the function: in this case getTempOfTmrw()

So, what is it here?

It’s up to you to find it.

Here are more explanations.

Many documentation and tutorials use the words parameters and arguments interchangeably and it’s confusing.

And here is an example that shows you the difference between the two:

function myFunction(parameter) { 
/* parameter gets its value from argument variable 
passed to myFunction() call. */

/* inside a function, the variable parameter 
should be used, not argument. */

/* i.e. You should not use argument variable inside the function */

console.log(parameter) /* output: This is an argument when 
it is passed into myFunction call, and parameter 
when used inside the function */
}

...

var argument = "This is an argument when passed into 
myFunction call, and parameter when used inside the function.";

myFunction(argument);

Oh, I think you’re talking about the “tomorrow” I left there (“function getTempOfTmrw(tomorrow)”) I know I shouldn’t have change it because it indicates where you can change the code, but even with the original value they give (“function getTempOfTmrw(avgTemperatures)”) it’s always the same result.

Ok, thanks for the answers!! I found what I was doing wrong.

Good luck & happy coding.