$%#Confirm the Ending$#%

Tell us what’s happening:
i have no idea why it doesn’t work !

Your code so far

function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  var nwstr = str.split("");
  if ( str.substr(nwstr.length-1-target.length ,  nwstr.length-1 ) === target) 
      return true;
    return false;

confirmEnding("Bastian", "n");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36.

Link to the challenge:

You’re misunderstanding how to use substr. The first argument is the starting point. Your math is a bit off there. And the second argument is the is the length you want to select. Isn’t the length you want to select the length of the target?

1 Like

This says you’re looking for a property literally called “length-1-target”. You need to review using square brackets to access properties, eg someStr[someStr.length - 1]

1 Like

No, it evaluates to the same as nwstr.length - 1 - target.length. To access property names containing hyphens, you need to use bracket notation.

const obj = {
  'a': 0,
  'a-1': 0

obj.a-1 //=> -1
obj['a-1'] //=> 0
1 Like

You do not use split() because String object has length property.
You omit -1 in the expression.

1 Like

Ah crap, you’re right I was half asleep this morning.

Thanks! i’ve done it, a little confuse at first argument :slight_smile:

Thanks! you were right, i used to think the second argument was the ending point :smile: