Use-destructuring-assignment-to-assign-variables-from-objects // Szabi

**Tell us what’s happening: **
Hello,

My code is using Destructuring Assignment and the function is working but when i Run it: “destructuring with reassignment was used” was not checked
Is this a bug or I just have the wrong code? (still learning)

Cheers,
Szabi

Your code so far



function getLength(str) {
  "use strict";

  // change code below this line
  const {length : length} = str;// change this
  let 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 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36.

Link to the challenge:

You have an extra step you don’t need. Think how you can re-factor the code.

1 Like

Thank you for the fast reply!
I’ve found the problem, it is simple :slight_smile:
const {length : len} = str;

But the question remains: I’ve still used Destructuring Assignment and it still was not checked

What was not checked?

1 Like

So in my first(not corrected) code, i used an extra code:
let len = length;
but i still used destructuring assignment, just not the cleanest way. On the Lesson side the “destructuring was used.” was with a red circle with an “X” instead of it being checked.

Try resetting and attempting it again.

1 Like

It works with my corrected code, but with the old one it does not. I’ve tryed in chrome dev tool and it works normally. The reason the lesson did not accept it is because I did not write the code exactly as it was intended. Thanks for the help, I have an issue with a similar case with “ES6: Use Destructuring Assignment with the Rest Operator to Reassign Array Elements” but i will make a separate post about that. Thank you again

This may be due to the way the tests are written. If you think that the test is not fair, raise a bug. Remember this is in beta.

1 Like

I know it’s a beta and it’s awesome! :slight_smile: I don’t know where i can report a bug, still new to this system.

which led me to

1 Like

Thanks! I will check if someone already posted this, if not, thank I might put it up

Thanks for this, it’s been bugging me for hours… However, I have one question; Which part of the code is actually calculating the length of the string?

I was expecting a str.length; in there or something similar.