Confirm the Ending Confusion Over Failure

Tell us what’s happening:
I returned to correct answer, but the test does not pass me. Am I not doing something right?

Your code so far


function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
 var spltstr = str.split("");

return spltstr[6];
}

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/69.0.3497.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/confirm-the-ending

It wouldn’t be much of an algorithm if all you had to do was hardcode the solution to one possible outcome.

  1. The function is supposed to return true or false.

  2. The function is supposed to compare the str argument with the target argument.

Check if a string (first argument, str) ends with the given target string (second argument, target).

Would someone mind checking my logic? If not, then that’s it’s okay. However, the reason I ask is that I would like to know that the reasoning behind the approach I took to this particular algorithm challenge (I passed) are valid and not just me thinking something wildly inaccurate (and therefore having got to my result through luck rather than logic).

If you would mind commenting on my logic, then I would very much appreciate it. Thank you.

I have included my logic below with relevant numbers as it relates to the code being discussed.

//1 //create a variable to contain information to be processed and assign to this variable product of subtracting the target.length from that of the str. the result of such should produce the amount of target not enfolding the str

//2//Here, the if statement demonstrates that when such a logic is included as part of the function of a substring method of str the result will be TRUE, meaning that target would be implicated as part of the function of str.substr(conEnd). If it is not implicated, then the statement is FALSE.


//1
function confirmEnding(str, target) {

 var conEnd = (str.length - target.length);

//2.
  if(str.substr(conEnd) !== target){
    return false;
  } else {
    return true;
  }
console.log(conEnd);
 
}

Solution and logic look good to me and it seems to pass the tests