Bug with Challenge?: Destructuring Assignment to Assign Variables from Objects

Bug with Challenge?: Destructuring Assignment to Assign Variables from Objects
0

#1

Tell us what’s happening:
Guys please help, I’ve read like three articles on destructuring and also looked through these forum posts. This seems really simple, use destructuring to assign an object property value to a new name. I followed the template but it keeps on not checking off that I indeed used destructuring, although the function returns the correct value.

If I’m missing something here please help, I appreciate it!

It seems like this challenge is new, in that when I press " get a hint" it takes me to a solution for a different challenge with the same name.

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


#2

You posted a template.

Can you share your code?


#3

Hey, that is my code, it was originally

const tempOfTomorrow = undefined;

which I changed to

const { tomorrow : tempOfTomorrow } = AVG_TEMPERATURES:

Sorry not sure how to post it better


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

function getTempOfTmrw(avgTemperatures) {
  "use strict";
  // change code below this line
  const  { tomorrow: tempOfTomorrow }= AVG_TEMPERATURES; // this is my answer
 //const tempOfTomorrow = undefined; <- thats what it originally was.
  // change code above this line
  return tempOfTomorrow;
}

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

#5

Because the challenge forces you to use the “use strict” directive, you can not reference variables which are not passed into the function. How about using a value which is passed into the function instead?


#6
const { tomorrow: tempOfTomorrow} = avgTemperatures;
 
/* Thank you so much, this worked.   so its important to enter in the parameter name instead of the specific function name, can you explain why I'm able to enter in the specific property name of that function thought?  Again I really appreciate the answer Randell!

-Eric */