Use Bracket Notation to Find the Nth Character in a String - pls confirm?

Tell us what’s happening:

I understand the point of the lesson is to create the correct code. However, it also says that the " The thirdLetterOfLastName variable should have the value of v ." So I try to check it in the firefox console, and it comes back as undefined.

Is this because I am simply defining two variables, and not asking it to do anything with them?

When I add a third line, as in:

var lastName = "Lovelace";
var thirdLetterOfLastName = lastName[2];
thirdLetterOfLastName;

Then it does return a value of “v”.

So is my interpretation correct?

Your code so far


// Example
var firstName = "Ada";
var secondLetterOfFirstName = firstName[1];

// Setup
var lastName = "Lovelace";

// Only change code below this line.
var thirdLetterOfLastName = lastName[2];


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0.

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

If you want to see the value of thirdLetterOfLastName in the browser’s console, you will need a console.log statement:

var lastName = "Lovelace";

// Only change code below this line.
var thirdLetterOfLastName = lastName[2];
console.log(thirdLetterOfLastName); // should display v
1 Like

OK yeah that makes more sense. However, why was it previously coming back as “undefined” when I didn’t have that third line in there?

But in a sense, I’m on the right path… I needed to tell it to do something with the information, right?

Thanks for your reply, by the way :slight_smile: