Why litral regex is not working here?

Tell us what’s happening:
Describe your issue in detail here:

I’m using Regex to find the target string. im using the literal syntax for this. why isn’t it working?

  **Your code so far**

function confirmEnding(str, target) {
// console.log(str,target)
const check=/target$/gi;
return check.test(str)

confirmEnding("Bastian", "n");
  **Your browser information:**

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36

Challenge: Confirm the Ending

Link to the challenge:

target is a parameter and essentially a variable. You can’t put a variable inside a regex like that. Use the regex constructor function.

you’re right! i didn’t notice because I was confident of the result. Thank you!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.