Confirm the Ending125

Tell us what’s happening:
I can’t figure out why this doesn’t work it only fails on one test

Your code so far

function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  return str.indexOf(target)==str.length-target.length;


confirmEnding("Bastian", "n");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36.

Link to the challenge:

Your algorithm would fail many other cases which are not tested here. The issue is indexOf returns the first index (left-most) where target is found. In the case of “Congratulation”, there are not instances of “on”. You want the index of the last occurrence of target instead of the first.