Hi I’m confused about what’s happening in the console window
my code is producing an unexpected output. Here’s my code.
function trueOrFalse(wasThatTrue) {
// Only change code below this line
if (wasThatTrue) {
console.log("Yes, that was true");
return "Yes, that was true";
}
console.log("No, that was false");
return "No, that was false";
// Only change code above this line
}
trueOrFalse(true);
output it’s producing:
// tests completed
// console output
Yes, that was true
Yes, that was true
No, that was false
Yes, that was true
No, that was false
Yes, that was true
why is it returning both Yes and No no matter what parameter I pass to trueOrFalse()??
I think the reason is that the page is programmed to pass its own test cases (you can see them on the left side, below the assignments). It doesn’t look like we’re supposed to use our own function calls (hence the instruction // Only change code above this line Just my thought, anyway
The answer is the same as the last time you asked about the output of tests.
When you click the ‘Run Tests’ button, freeCodeCamp runs a series of pre-written tests that use the function you wrote. Some of those tests call your function with a true condition as the argument, and some tests call your function with a false condition as the argument.
You are seeing the result of the console log statements you added inside of your function as each of the tests in the freeCodeCamp test suite call your function.