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

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

#1

Tell us what’s happening:

third-to-last letter is not firstName[firstName.length - 3]

Correct one is
firstName[firstName.length - 4]//Gives third-to-last as index starts from 0. Please update your example and test-cases.

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.length-2];


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 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


#2

Thank you for helping make FCC better. Bugs should always be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible. There is already a reported bug that is causing a small subset of campers to have no certificate sections on their settings page.