This task requires that you write a function that takes two arguments. The first argument is a string called str
and the second argument is a string that our target ending named target
. The task is to verify that the ending of str
is identical to the target ending. The instructions indicate to use the .substr()
method to compare the endings to the targets. The problem I have is that there are going to be multiple starting points and length arguments for the .substr
method since the target endings can be of variable length. Take a look at my attempt to solve this issue and please direct me in the right path.
function end(str, target) {
var start = str.length - (target.length - 1);
if(str.substr(start, str.length) == target){
return true;
} else {
return false;
}
}
end('Bastian', 'n');