Build a Confirm the Ending Tool - Build a Confirm the Ending Tool

Tell us what’s happening:

Got it to pass all but one. It returns true because the n in “specification” and the n in “frozen” both end in n, so it goes to true. I’m not sure what to do next to verify that.

Your code so far

function confirmEnding(string,stringCheck){
  
  //gives the index number of last index of stringCheck within string
   const stringLastOccurenceStartsWith = string.lastIndexOf(stringCheck)
  
  
  //using these to do the checks 
  //gives the first letter of the first occurrence of stringCheck
  const lastStartsWith = string[stringLastOccurenceStartsWith]
  console.log("Last Occurence of stringCheck in String: " + lastStartsWith)

  //gives the first letter in stringCheck
  const stringCheckStartsWith = stringCheck[0]
  console.log("First letter in stringCheck: " + stringCheckStartsWith)

  //give the last letter in the string
  const stringEndsWith = string.slice(string.length-1)
  console.log("Last Letter in String(should): " +stringEndsWith)

  //gives the last letter in stringCheck
  const stringCheckEndsWith = stringCheck.slice(stringCheck.length-1)
  console.log("Last letter in stringCheck: " + stringCheckEndsWith)

  //maybe need to checking half the word


  if(lastStartsWith === stringCheckStartsWith && stringEndsWith === stringCheckEndsWith){
    console.log("true")
    return true;
  }else {
    console.log("false")
    return false
  }
}

confirmEnding("Connor", "n")

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

Your browser information:

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

Challenge Information:

Build a Confirm the Ending Tool - Build a Confirm the Ending Tool

1 Like

Refactor to check that the end of string is the entire stringCheck.

2 Likes

This is a simple solution

code removed by moderators - please do not post solutions
1 Like

hi @pak2601

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

1 Like