Find the Length of a String 2019

Tell us what’s happening:

Can anyone tell me why the code is not working. I followed the example but I seem to have made a mistake somewhere.

Your code so far


// Example
var firstNameLength = 0;
var firstName = "Ada";

firstNameLength = firstName.length;

// Setup
var lastNameLength = 0; 
var lastName = "Lovelace";

// Only change code below this line.
var lastNameLength = 8; 
var lastName = "Obsiye";

lastNameLength = lastName.length;   


Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/find-the-length-of-a-string

Hi! I see here you’re trying to reassign the length property to a var containing lastname, to an updated value of lastname.length and youd like that set to 8. The thing is lastname.length is = to 5 .

Obiseye = 5 string characters so i dont think you can reassign it to more characters than the string already contains.

If you’re trying to find the length. Youd simply go

Console.log(lastname.length); for example and it would print to the console 5.

Hope i could help!

1 Like

Edit: Obiseye is = 6 characters in string length.

Strings and arrays are 0 index based meaning they start from 0 not 1.

1 Like

it should be 6 as a result of a string…

// Only change code below this line.
var lastNameLength = 8; 
var lastName = "Obsiye";

lastNameLength = lastName.length;   

console.log(lastNameLength);
1 Like

The issue is that you are reassigning lastName, instead you need to work with the variable that is already assigned

var lastName = "Lovelace"

You also don’t need to initialise lastNameLenght.

It seems you got how it works, but the tests can’t know what you used to get that result without checking exactly what you wrote

So, below the “only change code below this line”, you need to write only

lastNameLength = ...
1 Like