For future reference, always include a link to the challenge.
Yes, you can definitely use a regular expression to solve this challenge. The issue with your code is that you can’t include a variable like that to create an expression.
let lastRegex = /target$/;
This is literally looking for the string “target” at the end of the string. You’ll want to use a RegExp object instead.
Anyone interested in the solution to my question the correct code is
function confirmEnding(str, target) {
return new RegExp(target + '$').test(str);
}
Which basically confirms whether target is at the end and nothing comes after at. I have understood it as "check whether after target there is nothing "