Basic Algorithm Scripting - Confirm the Ending

Tell us what’s happening:

My code passes the tests so i’m not entirely sure if this is where I should put my question.
After I finish the challenges, I usually go to the challenge guide to check the solutions and see if there is a simpler way to write my code.
But when I checked the solutions, it seems none are quite the same my code.
Is the fact my code passes a bug?

Your code so far

function confirmEnding(str, target) {
  for(let i = target.length; i > 0; i--){
    if(target[target.length - i] != str[str.length - i]){
      return false;
    }
  }
  return true;
}

confirmEnding('Bastian', 'n');

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Mobile Safari/537.36

Challenge Information:

Basic Algorithm Scripting - Confirm the Ending

1 Like

no, your code passes because it does what it is meant to do. An algorithm like this can be solved in a lot of different ways

@ Coo,
Your code is totally valid! It may not look like the solutions in the guide, but it works just fine and passes all the tests, which means it’s doing exactly what it’s supposed to. You’re using a loop to compare the end of the string to the target, and that’s a perfectly good approach. There’s no bug here—just a different (and still correct) way of solving the problem. Keep experimenting and checking other solutions—it’s a great way to grow!