Problem withConfirm the Ending challenge

Tell us what’s happening:
return a should return true or false. no?

Your code so far

function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  var len = str.length;
  var con = target.substring(target.length - len); 
  var a =  con === str;
  //return con === str;
  return a;

confirmEnding("Bastian", "n");

Your browser information:

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

Link to the challenge:

Why are you comapring con with str?

Because con is the last str words. Using the node console here when I compare them it outputs ‘true’

Yes, with your code, a is returning a true or false value for each test case.

Your logic is not correct in order to pass the challenge, but your assumption about the possible values of a is correct. To see what you are comparing (con and str) to assign to a, put a console.log statement before or after the var = con === str; line.

console.log(con, str); // you may be surprised at what is displayed

To view the browser’s console, use Ctrl+Shft+J in Chrome.

It does return true or false, but I think that you have str and target flipped in your understanding of the problem.

console.log(con, str)
n n

no surprises.

You must have changed your code, because when I run what you have posted above, I get:
Bastian n

oh I figured out! I was testing my code on the terminal (with node) instead of in the browser, I must have confused str and target on the FCC page :s.

function confirmEnding(str, target) {
var endChars = str.substr(str.length - target.length);
return (endChars === target);

confirmEnding(“Bastian”, “n”);