Confirm the Ending HELP

Confirm the Ending HELP
0

#1

I am having a problem only with the case when it is the word --> “Open sesame”, “same”

function confirmEnding(str, target) {
var strlength= str.length;
var strArray= str.split(" ");
var arraylength = strArray.length;

if(str.substr(strlength-1)==target || strArray[arraylength-1]==target){
return true;
}
return false;
}

confirmEnding(“Open sesame”, “same”);


#2

Try logging out to the console the conditions in your if statement to see exactly what you are testing. The first condition in the if statement, in this case, is simply the character ‘e’. The second condition is the entire word ‘sesame’. Think about how you would reference the end of str using str.substr(). Look into how negative numbers work in substr().


#3

thank you friend. I made the changes and now is Ok