Problem withConfirm the Ending challenge

Problem withConfirm the Ending challenge
0

#1

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:


#2

Why are you comapring con with str?


#3

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


#4

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.


#5

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


#6

console.log(con, str)
n n

no surprises.


#7

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


#8

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.


#9

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

confirmEnding(“Bastian”, “n”);