Use Bracket Notation to

You should use bracket notation…
I can’t get this right… Please help me.

Your code so far


// Example
var firstLetterOfFirstName = "";
var firstName = "Ada";

firstLetterOfFirstName = firstName[0];

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

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


Your browser information:

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

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

Hi @Karons,
var firstLetterOfLastName = “”; //assign a empty string to the variable
var lastName = “Lovelace”; // assign string Lovelace to the variable
var firstLetterOfLastName = “L”; // assign string L to the variable
var lastName = “lastName” [0]; //take the character at index 0 of the string and assign it to the variable.

Is this what you were asking about?

assign index 0 of the string to a new variable? What is the 0 index of the string? L?

In here “last name”[0], we are directly taking the first character of the “lastName” string. So last name variable would be equal to I. In that line lastName isn’t a string variable name. “lastName” is a string which is unassigned to a variable. In this case we are directly taking the first character of the string “lastName”. “lastName” is a string, Its not the variable lastName defined before (var lastName).
lastName === “l”

Got it now, thanks a lot.

Anytime. Glad I could help.