Get last character in Javascript

function lastLetter(word) {
return lastLetter[lastLetter.length[-1]];  //your code goes here...


//Uncomment the lines below to test your code

console.log(lastLetter("hello")); //=> "o"
console.log(lastLetter("goodbye!")); //=> "!"
console.log(lastLetter("ZeltoiD")); //=> "D"
console.log(lastLetter("I love Javascript")); //=> "t"

When i try to solve this exercise which is to return the last letter i get ‘undefined’. This is a very simple problem that i have been stuck on and i know the solution is simple. Anyone help please??

The syntax here is the problem along with using the function name instead of the parameter. What you want is the letter at the word.length - 1 index in the parameter word. You’re getting ‘undefined’ because you’re trying to return something that doesn’t exist. Give it another try. You need to return word[*index goes here*]. Click the spoiler if you get stuck:

return word[word.length - 1];
1 Like

Thank you so much midlindner!