Basic JavaScript - Find the Length of a String

I cant figure out how to do it please help me.

// Setup
let lastNameLength = 0;
const lastName = "Lovelace";

// Only change code below this line
lastNameLenght = lastName;

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Find the Length of a String

Link to the challenge:

“For example, if we created a variable const firstName = "Ada", we could find out how long the string Ada is by using the firstName.length property.”

Can you explain what you don’t understand about this example?

1 Like

The ‘lastNameLenght’ is initialized with the value of zero in the first code line.
Now, you have to assign the length of the ‘lastName’ variable to the ‘lastNameLength’ (after that the value will not be zero anymore). So apply the .length method on the ‘lastName’ variable in the last code line:

variableLenght = variable.method; ...this is guidance

Add the console.log(lastNameLength) to see the length of the string in question.

lastNameLenght = lastName;

lastName.lenght;
it dont work

You are spelling the property name wrong. It is length not lenght.

Same here.

Perhaps it’s because there is a typo in the word length? Try this instead:

lastNameLength = lastName.length;

i got it i just spelled it wrong

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.