Confirm the Ending if problem

What is wrong with the if statement? Why doesn’t return false?

function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  str = str.substring(str.length - 1);
  if(str) {
    return true;
  } else{
    return false;
  }  

}

confirmEnding("Bastian", "n");
1 Like

Try this: https://www.youtube.com/watch?v=9i9Rrw-VcZM
I made it for my students.

Thanks, but I need to understand the problem with if. Only using if(str) doesn’t compare anything?

Well… the str you’re using in the if statement returns true, because it’s not empty.
Only an empty string will return false.

Also you might want to do something with that target variable too…

Thanks, i always have doubt about arguments and statement if and else.

1 Like

Maybe this will help: https://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/

Thank you for the link.