Confirm the Ending Bastian "n"

Hey! I can’t seem to figure out why the Bastian example won’t return true. Any help would be super appreciated. Thanks!

function confirmEnding(str, target) {
  if(target.length === 1) {
    if(target === str.charAt(str.length)) { return true; }
    else  if(target !== str.charAt(str.length)) {return false;}
  }
  
  else if(target.length > 1) {  
    if(target.charAt(target.length) === str.charAt(str.length) && target.charAt((target.length) -2 ) === str.charAt((str.length) -2)) {
    return true; }
  else return false; }}

confirmEnding("Bastian", "n");

try str.charAt(str.length-1) remember charAt starts counting from 0

1 Like