Basic JavaScript - Find the Length of a String

Tell us what’s happening:

Hey need help checking my code because my lastName.length can’t equal 8 for some reason.

Your code so far

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

// Only change code below this line
lastNameLength = 8;
const lastName = lastName.length;

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4.1 Safari/605.1.15

Challenge Information:

Basic JavaScript - Find the Length of a String

This is invalid, you can’t re-declare a const or change its value.

you need to use lastName.length to set the lastNameLength variable instead of the value 8.

Here is the task:

Use the .length property to set lastNameLength to the number of characters in lastName.

Reset your challenge and try again.

1 Like

First remove the line lastNameLength = 8 from your code.
You have to assign the length of the value of lastName variable, i.e Lovelace. The length of Lovelace is 8. You have to assign it by the .length method of string.
Example:

const var = "Marry";
const varLength = 0;
// Length of var variable
varLength = var.length;
// Now varLength is 5

Here, the length of the value of var variable (Marry) is assigned to the varLength.

1 Like

Appreciate. You a magnificent tutor.

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