Confirm the Ending - not all goals met

Hey All! I feel really close to completing this one! I’m getting most of the check marks down on the goal section, but I have a few where I should be getting a false statement but Instead prints true.

What I did was try to take out the possibility of a case sensitive mistake, as well as using the includes() built in method to search for anything containing the ‘target’ parameter. Am I on the right track? Any way to guide me without giving an answer away and make me think about it would be so greatly appreciated. Thanks guys.

So far, you are successfully checking if the string includes the target. However, you aren’t specifically checking if the string ends with the target. :slightly_smiling_face:

2 Likes

Darn it! I was looking up substring() and I clicked a stack overflow link and the link gave away the answer :worried: now I feel like I didn’t earn it .and I was close too.

Accidental spoilers are the worst kind :sweat_smile:.

That being said, seeing the answer (especially by accident!) is not the end of the world - take the time to analyse the solution and make sure you really understand what the code is doing. And if you feel comfortable with it, try to find another way to solve it. :slight_smile:

2 Likes

Thank you @nhcarrigan.

I am trying to redeem myself, haha. So this was my answer to the challenge:

function confirmEnding(str, target) {
  let lowerCaseStr = str.toLowerCase();
  let lowerCaseTarget = target.toLowerCase(); 
  if(lowerCaseStr.substring(lowerCaseStr.length - lowerCaseTarget.length) === lowerCaseTarget){
    return true;
  } else {
    return false; 
  }
  
}

console.log(confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "are"));

However, I tried to research another way besides .endsWith() that I could use, and saw that I could use slice and get the same answer:

function confirmEnding(str, target) {
  let lowerCaseStr = str.toLowerCase();
  let lowerCaseTarget = target.toLowerCase(); 
  if(lowerCaseStr.slice(lowerCaseStr.length - lowerCaseTarget.length) === lowerCaseTarget){
                
    return true;
  } else {
    return false; 
  }
  
}

console.log(confirmEnding('hot cross buns','buns'));

I realize that slice is slightly different than substring, however, in this case it still works! Hopefully that is enough of a redemption lol. Thanks again!

1 Like

I’d say it looks like you’ve learned the concept - which is the point of each lesson. :slight_smile:
Nice work!

1 Like