Hi, calling the function with the requests give the same result of the requests, but the code doesn’t pass.
function confirmEnding(str, target) {
let a = target + "$";
let b = new RegExp (a);
console.log(b.test(str));
if(b.test(str)){
return true;
}
}
confirmEnding("Bastian", "n");
**Your browser information:**
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0
Challenge: Basic Algorithm Scripting - Confirm the Ending
That will display either true or false because the method test returns either true or false. So knowing that, do you think you could shorten up this function? The test method is doing all the work for you. It returns exactly what you need your function to return. How can you use that to make your function cleaner? I’ll give you a hint, you only need one line of code after the two let statements.
I forget to erase the print statement, if you meant that.
function confirmEnding(str, target) {
let a = target + “$”;
let b = new RegExp (a);
if(b.test(str)){
return true;
} else{
return false;
}
No quite what I meant. Your solution is perfectly fine, it works. But it has more lines of code than it really needs. As I mentioned in my last post, you can literally solve this with just one line of code (a return statement) after the two let statements. So total lines of code is 3. Remember, the test method is already returning exactly what you want your function to return. Let it do all the work for you.