Confirm the Ending[Help]

Tell us what’s happening:
I can’t seem to get the 4th and 5th part’s which are, “confirmEnding(“He has to give me a new name”, “name”) should return true.” and also “confirmEnding(“Open sesame”, “same”)”. Could it be that within the loop it’s only getting the last letter in the string?

Your code so far

function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  
  var splitStr = str.split(" ");
  for (var i = 0; i < str.length; i++){
     var k = str.slice(-1);
    if (k == target){
        return true;
      }

  }
  
  return false;
}

confirmEnding("He has to give me a new name", "name");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36.

Link to the challenge:

Yes it gets the last letter every time. If you want to use this approach you have to do
var k = str.slice(str.length -1 - i); . You can also do it without a loop since you know the length of the target :wink:

Lastly, your var splitStr = str.split(" "); is contributing nothing to the rest of the code. Remove it.