Using bracket notation

**Tell us what’s happening:**plz tell me what I am doing wrong
they are saying that lastName is not defined

Your code so far// Setup
var firstLetterOfLastName = “”;
var lastName = “Lovelace”;

// Only change code below this line
var firstLetterOfLastName = lastName;
var firstLetter = lastName[0];


// Setup
var firstLetterOfLastName = "";
var lastName = "Lovelace";

// Only change code below this line
var firstLetterOfLastName = lastName; 
var firstLetter = lastName[0];

Your browser information:

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

Challenge: Use Bracket Notation to Find the First Character in a String

Link to the challenge:

firstLetterOfLastName should have the bracket notation on it.

Maybe clarifying this a bit.

firstLetterOfLastName is the variable that should contain the first letter from the string assigned to the lastName variable.

You created a new variable firstLetter that you were not asked to create.

1 Like

i don’t understand what is the bracket notation

Bracket notation is a way to refer to different letters in a string for example in a string Hello the ‘H’ has the postition of 0, ‘e’ has position 1, first ‘l’ has postion 2 second ‘l’ has position 3 and so on. Just remember that position number starts with 0 and not 1 it goes 01234… So if this Hello string was in a variable word then word[0] means ‘H’ word[1] means ‘e’ and so on. I hope that makes sense.

You already did it, you are just assigning the letter to the wrong variable, one you were not asked to create.

It tells you what line to change:

firstLetterOfLastName = lastName; // Change this line

Instead you did this:

var firstLetter = lastName[0];