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

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

// Setup
const lastName = "Lovelace";

// Only change code below this line
const lastLetterOfLastName = lastName; // Change this line

Your browser information:

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

Challenge: Basic JavaScript - Use Bracket Notation to Find the Last Character in a String

Link to the challenge:

Help
Hey Can Someone Pls Help Me Understand This

You use the square brackets [] at the end of the variable to isolate the specific letter. letter. Because JavaScript uses 0-based indexing, that means the first letter has index 0 and the last letter of a string has index string.length - 1.
Edit the solution out by moderator.

@clariguy please refrain from share solutions

@Ramanuj Is @clariguy answer sufficient?

If not feel free to ask about which part you don’t understand.

Hey Ramanuj, let me break your problem into steps.
1)
You need to find the last character in the string for example -“Ramanuj” string contains 7 characters and the last character is “j”.
2)
string and arrays are index or numbered starting with 0 so in string “Ramanuj” character “R” is at index 0 and the last character “j” is at 6 index and not 7 as index start from zero and not one.
3)
To access any character in string or element of an array we use bracket notation.
var str = “Ramanuj”;
var firstCharacter = str[0] ;
console.log(firstCharacter) // “R”;
4)
to find the length of an array or string we use length property.
var str = “Ramanuj”;
var len = str.length;
console.log(len) // 6 as index start from 0.

hope these steps help :slight_smile: happy coding!!