Confirm The Ending challenge feedback please. :)

Confirm The Ending challenge feedback please. :)
0

#1

Hello fellow coders! I would like your feedback on this challenge that I just completed. I did it in less than an hour so I feel it’s not very simple and clean. Any ideas on how I can make it better? Any feedback would be great! Good or bad! I really want to learn good techniques. My code is below:
function confirmEnding(str, target) {
/* check target against str by counting amount of letters in target and checking characters in str*/
//compare ending characters of str with characters in target.
var stringLength = str.length;
var targetLength = target.length;
var strArray = str.split("");
var targetArray = target.split("");
var j = 0;
//start comparing value from the length of string minus length of target

for (var i = (stringLength - targetLength); i < str.length; i++) {
if(strArray[i] === targetArray[j]) {
j++;
return true;
}
else return false;
}
}

confirmEnding(“Bastian”, “n”);


#2

In the challenge, they ask you to use one of the Javascript substring methods.

I suggest you read the documentation and learn about them.
A hint:
"Sebastian".substr(-3) // returns "ian" "ian".length //returns 3 confirmEnding("Sebastian", "ian") // <- You can implement the hint I gave you in this function.

The MDN is your friend :wink: