function getLength(str) {
“use strict”;
// change code below this line
const len=str; // change this
// change code above this line
return len.length; // you must assign length to len in line
}
console.log(getLength(‘FreeCodeCamp’));
function getLength(str) {
“use strict”;
// change code below this line
const len=str; // change this
// change code above this line
return len.length; // you must assign length to len in line
}
console.log(getLength(‘FreeCodeCamp’));
Can you format your code and add a link to the exercise?
thats the link to the challenge
Hey @zeshan880,
Javascript is an object oriented language.
So, even the string is an object in javascript.
Now, think of string as any normal object and length as its one of the properties.
var string = {
"length" : 6
}
Now read the instruction in the challenge carefully.
They want this length property of str object to be assigned to the len
variable.
Try solving now.
Does that help?
Hello!
Think about len as an object, if it is an object then, it has properties, in this case your object const len
has 1 property that should be length
so, remember from previous lessons how to assign a value to an object property, that is:
obj.property = “value”
Implement the same but with the challenge being:
const len => Object
length => property of “len” object
str.length => value to assign to len.length
Hope this helps!
i cant solve it i had tried a lot
Could you post your latest code?
This should work:
// change code below this line
const { length: len } = str; // change this
// change code above this line
After reading the challenge, you should have noted that you are using destructing variables assignment. The code above can translate to this:
Assign the value of the property length
to the variable len
searching from the object str.
Hope this helps!
Hi,
Sorry about that, didn’t know it could not be posted.