Check if a string (first argument, str
) ends with the given target string (second argument, target
).
It seems that statement ‘return (/target$/.test(str));’ always return false. I am not sure why. Advice much appreciated.
function confirmEnding(str, target) {
/*if regex (target) matches the end of the string (str), statement should return true. If not, it should return false*/
return (/target$/.test(str));
}
confirmEnding("Bastian", "n");
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
Please use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks are not single quotes.
1 Like
Hello and welcome to the FCC community~!
You’ve put target
in within your Regex delimiters //
so it seems the code is looking for a literal string “target”, not the value for the target
parameter.
1 Like
Thank you! Feels great to be here!
Sorry about that. I’ll make sure to correct it with my next post.