Basic Algorithm Scripting - Confirm the Ending

Tell us what’s happening:

I’m having trouble with this question. I don’t understand where to locate the .endsWith().

Your code so far

function confirmEnding(str, target) {
  return str;
}

confirmEnding("Bastian", "n");

Your browser information:

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

Challenge Information:

Basic Algorithm Scripting - Confirm the Ending

Please show us the code you have tried to write so far.

Here it is:

function confirmEnding(str, target) {
  if (str.endsWith(target)) {
    return str;
  }
}

Trying this, I get it all wrong.

  1. Your code should not use the built-in method .endsWith() to solve the challenge.

You can’t use .endsWith(). You need to mimic the behavior of .endsWith().

Oh, I should’ve read the instructions. But could you please give me some hints?

What does endsWith() do? You need to code that

How do you return the last char of a string?

endsWith() checks if a string ends with a specified sequence of characters - returns true if this requirement is met, returns false otherwise. Bracket notation is another way of returning a string.

These are question you need to answer for yourself, not for me, it’s not a test or anything.

Are you able to code that now? Please let us know if you have any questions.