Tell us what’s happening:
How does subtracting one(1) from the strings length character gives us the last letter of the string?
What is length exactly?
What is after the last character?
Plz help . Appreciated.
Your code so far
// Setup
var lastName = "Lovelace";
// Only change code below this line
var 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/85.0.4183.121 Safari/537.36.
Challenge: Use Bracket Notation to Find the Last Character in a String
Thank You for doing so much just to explain a problem to me . I really appreciate it.
However:
I still can’t understand the mystery behind -1.
What exactly does the subtraction does?
Even if I subtract -1 , won’t I still have other alphabets?
Below I will write a string, and below it the indexes of each character:
"Lovelace"
01234567
the length of the string is 8, the last character index is 7, if you don’t know what’s the length of the string, you can get last character by taking the character at index “string length minus one”