Stuck on "Use Destructuring Assignment to Assign Variables from Objects"

Stuck on "Use Destructuring Assignment to Assign Variables from Objects"
0

#1

Tell us what’s happening:
Hi friends,
I’m stuck here I need help please.
Here is the challenge link: https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-objects
I completely don’t understand though, I got everything right (according to the researches I did).
I won’t be surprise if it’s just some bugs or things like that.

Thanks in advance!

Your code so far


function getLength(str) {
  "use strict";

  // change code below this line
  var length = {x: str.length};
  const {x: len} = length;
  // change code above this line

  return len; // you must assign length to len in line

}

console.log(getLength('FreeCodeCamp'));

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-objects


#2

I managed to fix it.
Some hints:

  • 1) Make sure str does have a property named "length" which obviously contain the length of the given string
  • 2) Assign the "length" property to a local variable named "len" using destructuring assignment in 1line which is the "get the field x and copy the value into a" method
  • Keep this in mind and everything will be alright