Confirm the Ending : Logic is failing for one test case

Confirm the Ending : Logic is failing for one test case
0.0 0

#1

Tell us what’s happening:
All the test cases except one, doesn’t seems to like my code. Can anyone of you please let me know why?
FCC is asking when the input is like this,
confirmEnding(“Walking on water and developing software from a specification are easy if both are frozen”, “specification”) should return false.

Your code so far

function confirmEnding(str, target) {
    // console.log(str);
    var strEnd = str.substr(-1);
    var tarEnd = target.substr(-1);
    if(strEnd === tarEnd){
        return true;
    }
    else{
        return false;
    }

}

confirmEnding("Bastian", "n");

Your browser information:

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

Link to the challenge:


#2

Your code is only comparing the last letters of str and target (as opposed to comparing the whole target against the end of str).


#3

Cool…thanks @kevcomedia
adding this
var strEnd = str.substr(-target.length)

worked just fine!