Basic Algorithm Scripting - Confirm the Ending

i wanted to confirm the existence of the target at the end of the string using decremented For loop :

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

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

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

Challenge: Basic Algorithm Scripting - Confirm the Ending

Link to the challenge:

Your code will only work if the target is only one character. You need to figure out how to make it work for other cases.

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