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’.