Tell us what’s happening:
I have managed to do resolve this challenge but I need someone to give me the breakdown of how it happened. thanks
Your code so far
var firstName = "Ada";
var lastLetterOfFirstName = firstName[firstName.length - 1];
var lastName = "Lovelace";
// Only change code below this line.
var lastLetterOfLastName = lastName[lastName.length - 1];
Your browser information:
User Agent is:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:62.0) Gecko/20100101 Firefox/62.0.
Link to the challenge:
you have a string stored in the variable lastName
the string is Lovelace
To access the characters of the string , you use something called bracket notation
this will give us the character at location zero which is L
this will give us the character at location one which is o
If you don’t know how long your string is and you want to access the last character you need to ask first about the length.
For eg. Lovelace has a length of 8
so to get the last letter e we should write
lastName[8-1] as seven is the eighth position (remember that zero is the first position)
And in order to write ‘7’ without actually counting the length of each string , we let the computer do it like this
lastName[lastName.length - 1]
hope this helps
wow, that’s the best explanation ever!
thanks a ton!