Last task will not pass

Last task will not pass
0

#1

Tell us what’s happening:
My code won’t pass the last task for some reason. ("trueOrFalse(false) should return “No, that was false” ) I have triple checked caps and spacing as well.

Your code so far

// Example
function ourTrueOrFalse(isItTrue) {
  if (isItTrue) { 
    return "Yes, it's true";
  }
  return "No, it's false";
}

// Setup
function trueOrFalse(wasThatTrue) {
  if (wasThatTrue); {
   return "Yes, that was true";
  }
   return "No, that was false";
  
    
}
// Change this value to test
trueOrFalse(true);
trueOrFalse(false);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36.

Link to the challenge:


#2

You have a semi-colon at the end of your if statement condition which is causing trouble.


#3

smh…Thank you. I’m curious tho. Why does the “true” test work, but not the “false” test? Wouldn’t both tests fail if an error occurred in my code prior to both the true and false return executions?


#4

Having that semi-colon at the end of the if statement condition makes JavaScript think that you have an empty statement there, and everything to the right of it is treated as no longer belonging to the if conditional and thus independent of it. So, no matter what you pass to the function, the line:

return "Yes, it's true";

will get executed everytime.


#5

ahh…I see. Thanks for the help and answering my Q.


#6

Remove semicolon from the if statement then see …It will work