Back to Freecodecamp

Basic Functions Exercise D

curriculum/challenges/english/blocks/top-basic-function-projects/661e17c6068359c3ccf2f4d8.md

latest610 B
Original Source

--description--

Write a function, named lastLetter, that takes a string as a parameter and returns the last letter of the string.

--hints--

You should have a function named lastLetter.

js
assert.isFunction(lastLetter);

Your function should take in a string as a parameter.

js
assert.match(lastLetter.toString(), /\s*lastLetter\(\s*\w+\s*\)/);

You should return the last letter of the string.

js
assert.strictEqual(lastLetter('Sem'), 'm');

--seed--

--seed-contents--

js

--solutions--

js
function lastLetter(str) {
  return str[str.length - 1];
}