Help with algorithm confirm the ending

Hi guys,

Been trying to figure out why this solution doesn’t work for the algorithm confirm the ending.

To me it seems like this should work, but it keeps returning true. str.slice(-lengthOfEnd) is giving me end of the string (to the length of target) and it should be checking if that ending = target but it’s not evaluating is correctly for some reason. Any one have any tips?

     function confirmEnding(str, target) {

  
  lengthOfEnd = target.length;
  
  if (str.slice(-lengthOfEnd) === target);{
 
  return true; }
  

 return false;
  
}

confirmEnding("Connor", "n");

I believe the issue is you have a semicolon at the end of your if statement.

1 Like

There is a semicolon preceding the body of if statement. This is like saying:

function confirmEnding(str, target) {
    var lengthOfEnd = target.length;
  
    if (str.slice(-lengthOfEnd) === target);
 
    return true;
    return false;
}

As you can see your function always returns true.

Also, don’t need to explicitly return Boolean.

function confirmEnding(str, target) {  
    return str.slice(-target.length) === target
}

Lastly, you forgot to use var keyword for your lengthOfEnd variable.

1 Like

Oh wow I feel like an idiot :frowning:

Thanks so much