This post is more about how to think to resolve it. I had troubles initially and the breakthrough was when I started to subdivide the problem into simple tasks :
- read target
- count the target characters number
- take same number of characters from the end of the str and make a new string from them
- compare that new string with target string
-if equal ==> true - if not equal ==> false
What I took from this is that I was doing all wrong during the entire course up until now because I was trying to solve it globally, as a single question to find the answer to.
So in case there are others doing this same mistake please try to do this instead. It is so much better. Took me like 2 hours yesterday, doing it the “wrong” way and just 10 minutes today to solve the exercise.
P.S. this is my result:
function confirmEnding(str, target) {
let Ending = str.slice(-target.length);
if (target === Ending) {
return true;
}
else {
return false;
}
return str;
}
confirmEnding("Bastian", "n");