Basic JavaScript - Find the Length of a String

Tell us what’s happening:

I can’t make the lastNameLength be 8. I also don’t know how? I’ve watched the video over and over again but I still don’t understand it? could I please have some help on this question?

Your code so far

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

// Only change code below this line
let lastNameLength = lastName.length;
let lastName = "Lovelace";
console.log("Lovelace".length);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 OPR/111.0.0.0

Challenge Information:

Basic JavaScript - Find the Length of a String

Hi there! Remove all of your code except this

To check the length, just use the dot notation with the variable you want to check. (In this case, the variable is lastName)

you can do that, you need to avoid syntax errors like declaring the same variable twice, which breaks everything

Let’s figure what mistake you have done:

  • The lastName variable is already declared in third line. So remove the second unnecessary declaration from the 7th line.
  • See, the lastNameLength is already declared at the top. But you have also declared below which is causing syntax error. So remove the keyword let from the second variable lastNameLength.
  • You have get the length of lastName variable and stored it in the variable lastNameLength, so you can console it direclty. Replace “Lovelace”.length with lastNameLength in the console statement.

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