Tell us what’s happening:
So I solved this using regex, but the “native” solutions is this:
function confirmEnding(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
return str.slice(str.length - target.length) === target;
}
confirmEnding("He has to give me a new name", "name");
Just found it to be really clever. I’m new btw so my mind is still blown by these kinds of codes.
Your code so far
function confirmEnding(str, target) {
let regex = target;
let testString = new RegExp(regex + "$", "i")
let finalTest = testString.test(str);
return finalTest;
}
confirmEnding("Bastian", "n");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/confirm-the-ending