Okay, so I do not understand why this code doesn’t work. I’m not looking for a solution to the FCC exercise (I figured out another way), but rather just an explanation of why this doesn’t work because I’m not getting it.
function confirmEnding(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
let targetReg = /target$/;
let result = targetReg.test(str);
return result;
}
confirmEnding("Conner", "r");
This returns false. However, if I replace /target$/ with /r$/ it works even though target is equal to r when it’s passed in as an argument in the function.
Super confused, but thankful for the help.