'Confirm the ending' challenge

I need help understanding why my code doesn’t work.
‘Check if a string (first argument, str) ends with the given target string (second argument, target).’

function confirmEnding(str, target) {
   if (str.substr(str.length - 1) === target.substr(target.length - 1)) {
       return true;
     return false;

confirmEnding("Bastian", "n");

When I run the tests, all of the tests pass except this one: confirmEnding(“Walking on water and developing software from a specification are easy if both are frozen”, “specification”) should return false.
I am trying to understand why this particular test doesn’t pass, although the last characters of both arguments are ‘n’.

You are only checking if the last letter of the two strings matches. In the specific case that should return false, the last letters are the same: “… if both are frozen” and “specification”.

Basically your code does not work when target is larger than one character.

1 Like