# Help with algorithm confirm the ending

**URL:** <https://forum.freecodecamp.org/t/help-with-algorithm-confirm-the-ending/88824>\
**Category:** General\
**Created:** [February 18, 2017, 11:26pm UTC](https://forum.freecodecamp.org/t/help-with-algorithm-confirm-the-ending/88824 "2017-02-18T23:26:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rgebo21](https://avatars.discourse-cdn.com/v4/letter/r/c6cbf5/32.png) [@rgebo21](https://forum.freecodecamp.org/u/rgebo21)\
**Post date:** [February 18, 2017, 11:26pm UTC](https://forum.freecodecamp.org/t/help-with-algorithm-confirm-the-ending/88824/1 "2017-02-18T23:26:05Z")

</div>

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");
```

---

<div class="post-metadata">

**Author:** ![Randallfine](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/randallfine/32/9278_2.png) [@Randallfine](https://forum.freecodecamp.org/u/Randallfine)\
**Post date:** [February 19, 2017, 12:06am UTC](https://forum.freecodecamp.org/t/help-with-algorithm-confirm-the-ending/88824/2 "2017-02-19T00:06:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gunhoo93](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/gunhoo93/32/87162_2.png) [@gunhoo93](https://forum.freecodecamp.org/u/gunhoo93)\
**Post date:** [February 19, 2017, 12:07am UTC](https://forum.freecodecamp.org/t/help-with-algorithm-confirm-the-ending/88824/3 "2017-02-19T00:07:09Z")

</div>

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

```auto
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.

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

```

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

---

<div class="post-metadata">

**Author:** ![rgebo21](https://avatars.discourse-cdn.com/v4/letter/r/c6cbf5/32.png) [@rgebo21](https://forum.freecodecamp.org/u/rgebo21)\
**Post date:** [February 19, 2017, 3:11pm UTC](https://forum.freecodecamp.org/t/help-with-algorithm-confirm-the-ending/88824/5 "2017-02-19T15:11:11Z")

</div>

Oh wow I feel like an idiot ☹

Thanks so much

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 5:24pm UTC](https://forum.freecodecamp.org/t/help-with-algorithm-confirm-the-ending/88824/6 "2021-01-16T17:24:03Z")

</div>

Closed on January 16, 2021, 5:24pm UTC


