Tell us what’s happening:
I am trying to see if the target
parameter matches the end of the str
parameter without using the endsWith()
string method. I console.log()
each line of code and everything seems to be called/accesses properly.
What would be wrong with my logic below? I am trying to compare the last X indexes in the str
parameter. I would do that using .substring()
and starting from ((str.length - 1) - (target.length - 1))
Your code so far
function confirmEnding(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
str.substring((str.length -1)-(target.length-1)) === target ? true : false;
}
confirmEnding("Bastian", "n");
Link to the challenge: