Nth ChARACTER IN A STRING

  1. CONSIDERING STARTING FROM 0, WHY WOULDNT THE CODE BELOW BE EQUAL TO “C”
  2. PLEASE help

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

// Setup
var lastName = "Lovelace";

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

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

If lastName is "Lovelace", then var secondToLastLetterOfFLastName= lastName[lastName.length-2]; would create a variable named secondToLastLetterOfLastName and assign "c" to it. If you are encountering errors, it is probably because you declare secondToLastLetterOfLastName twice.

Thank you for your input

And the second time the variable is spelled wrong, so the test suit is just reading lastName as what you are passing as value to that variable