Help w/ JS challenge: suspected bug

Tell us what’s happening:
what’s happening is I used the code the way the challenge told me to, but I couldn’t pass the challenge for some reason. maybe a bug in the challenge…

Your code so far


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

firstNameLength = firstName.length;

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

// Only change code below this line.

lastNameLength = lastName.length;


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

You seem to have modified this line:

var lastNameLength = 8;

It should be equal to 0 there or the tests get confused, thinking you’re trying to get it another way

1 Like

Ok lastNameLength is 8 but that value should be got from the code below.lastNameLength should be equal to 0.Don’t write it directly:

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

firstNameLength = firstName.length;

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

// Only change code below this line.

lastNameLength = lastName.length;
1 Like

Thanks!! worked! maybe they should re-make the challenge and set the variable to 0

The starting value of that variable is 0, if you reset the code you can see it

1 Like

The variable was already set to 0 when the challenge starts. There is a comment that says “Only change code below this line”.

Your code should technically work, but test you fail is also checking that you did not change the declaration in the setup. I have created a PR (#35940) which creates an additional test which validates the user has not modified anything in the original setup. Also, I modified the last test to only check that .length was used in the solution. These two changes should make it easier to understand what should and should not be changed.

3 Likes