Need Help With (Confirm the Ending) missing one last concept

I’m missing just one thing that is how can I add that the test should target the last letter
and the whole last word and the last part of the last word all together I have just one last test to finish this challenge.
(please guide me) thanks

function confirmEnding(str, target) {

// pushing the last word into lastWord
let lastWord = [];
let letters = str.split(" ");
lastWord.push(letters[letters.length - 1]);

//making the regexp 
let reg = RegExp((target));
let result = reg.test(lastWord);

if (result) {
    return true;
} return false;

confirmEnding("Connor", "n") //  it should be false am getting true 

Challenge: Confirm the Ending

Link to the challenge:

A $ at the end of a regular expression tells it to target the end of the input.

/hello/.test("hello") // true
/hello/.test("hello world") // true
/hello$/.test("hello") // true
/hello$/.test("hello world") // false

That being said, I think using a regular expression is overcomplicated for this problem. Remember that you can compare strings simply with ===.

"hello" === "hello" // true
"hello" === "hello world" // false

What if you tried comparing the last letters of str to target?

but some of the tests ask for 2 letters or the last 4 letters of the last word

i did try

    let letters = str.split("").pop();
        if (letters === target){
          return true;
        } return false;

which will only pass the first test

You’re on the right track there, sort of.

For confirmEnding("Bastian", "n") you’d need to check "n" === "n"

For confirmEnding("Congratulation", "on") you’d need to check "on" === "on"

For confirmEnding("Connor", "n") you’d need to check "r" === "n"

and so on.

1 Like

ok one last thing just tell me should i be looping and pushing letters then check it or like poping more than one letter or I should be slicing or splicing the last word by the length of the target parameter

Whichever you prefer! You could use a loop to build up the string you’ll use to check, or you could use slice (or other string methods) to do the same, or you could find some way to append $ to the regular expression you were trying above.

1 Like

ok perfect thank you :+1: :+1:

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