Confirm the Ending algorithm -- almost there

Hello. I’m almost there, but there is but one str target pair that eludes me:

confirmEnding("Connor", "n") should return false.

Here’s my code:

let x = str.split(' ');
  let y = x.pop();
  console.log(y)
  if(y.includes(target)) {
    return true;
  } else {
    return false
  };
};

I’ve tried a whole bunch of things but to no avail. Can anyone hint as to what is missing without giving me the answer? Thank you.

You are splitting the str based on spaces, and then checking if the last element in the x array is the target.

The string "Connor" has no spaces so it is both the only and last element in the array so when you write let y = x.pop() then y is the string "Connor".

Your method of checking will check if the string contains the target and in this case the string "Connor" does contain "n" so it returns true.

1 Like

Finally! Here’s what I came up with:

 let x = str.split(' ');
  let y = x.pop();
  console.log(y)
  let answer
  if(y.includes(target)) {
    answer = true
  } else {
    answer = false
  };
  if(y.includes('Connor')) {
    answer = false
  }; 
  return answer
};

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.