Nth-to-Last Character in a String

Tell us what’s happening:

Your code so far


// Example
var firstName = "Ada";
var thirdToLastLetterOfFirstName = firstName[firstName.length - 3];

// Setup
var lastName = "Lovelace";

// Only change code below this line
var secondToLastLetterOfLastName = lastName[lastName.lenght -2];



Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-to-last-character-in-a-string

I think that hint on this problem is not correct because in programming if u go length -2 it’s telling me I in programming it the letter i but here in Lovelace -2 is c so basically in hint it says -2 is the 3rd letter from behind but in the actual challenge it’s the second letter from behind … if I’m wrong sorry but it just doesn’t make sense to me. Just got me confused cos it’s not the same thing.

You spelled “length” wrong.

I was typing fast =D it doesnt matter the problem is that in the word -2 on the challange is second from behind and -2 in the hint guide is 3rd letter
or maybe i’m just not looking right ^^

Use Bracket Notation to Find the Nth-to-Last Character in a String

Remember that the position of any character, is the length of the string, minus one, minus the number of characters after it . For example, if you are trying to find the third-to-last character of the following string:

var str = "Programming";
var secondToLastChar = str[str.length - 2]; // This is 'i'

As you can see, there is one extra character after ‘n’ (and that is ‘g’). but in the actuall challange i think it’s the second from behind ? -2 ( Lovelace ) so u get c but in the guide here it says -2 gives u I and not N and that’s what i dont understand cos if i go -2 here i get the second from behind and if i get -2 in the guide u would get letter i instead of n. :slight_smile: sry for wasting your time if it’s my mistake and i’m just not seeing anything cos i’m a newb :slight_smile:

There is an error in the comment. var secondToLastChar = str[str.length - 2] is ‘n’.

That’s what confused me <3 thanks a lot

The Guide articles are in transition right now. Once they’re migrated to the forum, we can begin fixing errors in them again.

No problem at all! I mean all of this is free and a huuuuge help. Thank you verry much for replying fast. U guys are awsome! :slight_smile:

I’m glad you’re enjoying it. Happy coding!