Confirm the ending with different ways

Tell us what’s happening:
I know from the solutions that it can be solved with slice method. But here, my code is true. I wonder why it didn’t pass the test. Could someone explain me how it happened?

**Your code so far**

function confirmEnding(str, target) {

let a = str;
let b = target;
let c = a.substring(a.length - b.length);

  return a === c;


confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification");

confirmEnding("Congratulation", "on");

confirmEnding("He has to give me a new name", "name");

confirmEnding("Open sesame", "same");

confirmEnding("Abstraction", "action");

**Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36.

Challenge: Confirm the Ending

Link to the challenge:

Shouldn’t you be comparing b and c not a and c?


These statements are both useless and problematic.
They are useless because str and target are already variables → there is no point in creating new ones with the same values.
Those are bad names. Force yourself to give variables resonable names. Once you write more complex code, navigating with variables having meaningless names “a, b, c, d, e, f, g…” is just REALLY hard and pointless.

Also it can be useful to find errors - for example if the variables meaningful names, you might notice your final check is “str === ending”, which doesn’t make sense.

1 Like

yeah lol .Thz buddy.

yeah yeah. Whatever I make new variables, it looked more confusing.Thz buddy, I will practice that.

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