Tell us what’s happening:
what next ?
Your code so far
function getLength(str) {
"use strict";
// change code below this line
const length =str.length; // change this
const 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/68.0.3440.106 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
@camperextraordinaire
I am confusing about destructuring because they use one kind example and ask me to do another type.
This is a little bit tricky because it seems like you are dealing with a variable & a string, but when using length
or any other method or property, you are also dealing with an object.
Here you can apply the ES6 destructuring assignment…
You may want to see this hint which will probably give you an idea to complete this challenge.
Mainly I am confusing to define the “len” and assign it to the length. that’s the problem.
I also got stuck with this for an hour, but then I found the solution thanks to the previous hint I shared with you.
Don’t give up. (It’s the same reasoning like in the examples. The only difference and the key is that you should know that you are dealing with an object, not just — like the first lessons teach — a simple variable holding a string.)
thanks for the tip. I got it.
Yeah, that is a bad problem. We don’t think of strings as objects, so how can you use destructuring? I think when JS sees that you are trying to use it as an object, it coerces it to the String
object type so that you can do it.
It’s a bad example because it involves knowledge that hasn’t been discussed. I’ll add it to the list of things to bring up in the curriculum.
1 Like