Wouldn't this substring() work?

Wouldn't this substring() work?
0.0 0

#1

Tell us what’s happening:

Your code so far

function confirmEnding(str, target) {
    if (str.substring(str.length -1 === target)) {
        return true;
    } else {
        return false;
    }
  }
  
  confirmEnding("Bastian", "n");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36.

Link to the challenge:


#2

You’re passing str.length -1 === target to str.substring. Maybe you intended just passing str.length - 1, then compare the result to target?

Then, think about what str.substring(str.length - 1) actually does. What value does it give you?