Confirm the Ending - Why won't my code pass tests?

Tell us what’s happening:

Why isn’t my code passing the tests? Any help appreciated. I thought str.length -1 gets the last value in the string.

Your code so far

function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  let strSplit = str.split(" "); // [B,a,s,t,i,a,n]
  if (strSplit.length -1 === target) {
    return true;
    return false;

confirmEnding("Bastian", "n");

Your browser information:

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

Link to the challenge:

You are comparing a number with character/s.

So it will probably always false.

1 Like