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

Tell us what’s happening:

I am not having issues with my code. I am wondering if this is a valid way to pass this “Lab”.

I have passed it, I just changed a few parts as to not give a completed project. I know this stated do not use endsWith which i didn’t use but it does not feel like the way this was intended to be passed.

I am submitting this for clarification on if its okay to pass this Lab the way I have using the pieces of code I left that should explain the method I used.

Your code so far

function confirmEnding(strInput, strCheck) {

  inputFlip.split("").reverse().join("");

  checkFlip.split("").reverse().join("");
  
  if startsWith(strCheck)) {
 
}

console.log(confirmEnding("Bastian", "n"))
console.log(confirmEnding("Congratulation", "on"))


Your browser information:

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

Challenge Information:

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

1 Like

Very funny solution. I would say this is basically the same as using endsWith and doesn’t follow the spirit of that instruction.

I think this would get you a very funny look from your programming teacher but you get 5 comedy points.

Once I typed it all out and Passed I felt evil but it was the only method that came to mind when I seen the Lab. Other than maybe a while loop that goes until it matches each character but I don’t know how I would start typing the code for that one.

Is their a way to use an if else statement to loop through and match characters then return true if it matches and if it reaches the end of the text with no match it would then be false.
Also thank you for the 5 points :sweat_smile:

Sounds like you are on the right track. Start small and test it as you go.

How do you suppose the endsWith method does it?

I am not sure. How I assume it works is that it has the input string and takes the length of the checking string from the end and === match on the two to see if it matches each other. At least that is the method I am about to do to see if I can pass the Lab this time.

Edit: I completed it another way.
Taking the -length to slice from the end and check it matches similar to what I said I thought endsWith( ) does. I am curious how I would change the if statement into a ? : version tenery I think it was called.

  if (inputEnd === strCheck) {
    return true;
  } else {
    return false;
  }
}

I was going to try something like.
let result = inputEnd === strCheck

But then how would I do the ? : is it just ? return true : return false.

But that method is literally check if true check if false.

Yes, this can be improved. I would not bother with a ternary though.

You are coding: If (inputEnd === strCheck) is true, return true, if (inputEnd === strCheck) is false then return false.

Why not just return the expression itself?

Oh yeah I forgot this was something that I can do with a return. Instead of the if statement just “return this === as true or false". Its the simple one line does what you need that gets me. I normally go the long way round.

You have been an incredible help. Thank you so much in taking the time to answer my questions. I also did have to google what you meant with just return the expression but I got their in the end.
Thank you again,
take care.

2 Likes