What Am I doing wrong with substr method?

Tell us what’s happening:
Describe your issue in detail here.
I know that this challenge can be solved using the slice method, however, I was curious why this code is passing at some tests and failing at some others?
I couldn’t detect a patern in the failed once.

  **Your code so far**

function confirmEnding(str, target) {
let length = target.length;
// eeven if I tried adding +1 it is still failing at the same words. 
// Is it taking  only one letter?
let result = str.substr(-1, length);
if(result == target){
  return true;
return false;

confirmEnding("Bastian", "n");
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0

Challenge: Confirm the Ending

Link to the challenge:

Try to add console.log(result) inside your function and see if the value is the one you think with the function calls in the failed tests

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