Basic JavaScript - Use Conditional Logic with If Statements

Hello, I passed the test, but something confused me about the example code in this step. Doesn’t the example code return both “It was true” and “It was false” if the condition is true? I checked it, and it did. But why? Is it intentional, or did I make a mistake while checking it?

Your code so far

function trueOrFalse(wasThatTrue) {
  // Only change code below this line
  if (wasThatTrue){
    return "Yes, that was true";
  }
  else{
    return "No, that was false";
  }

  // Only change code above this line

}

Your browser information:

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

Challenge: Basic JavaScript - Use Conditional Logic with If Statements

Link to the challenge:

How did it ‘return’ both when the condition is true? Each function call can only return once.

I did it like this

function test (myCondition) {
  if (myCondition) {
    console.log("It was true");
  }
  console.log("It was false");
}

test(true);

And the console showed this:

It was true
It was false

Was it incorrect to check it that way? I’m genuinely asking.

console.log and return do different things. return stops a function while console.olg does not.

1 Like

Thank you so much for the answer sir. It really clears up my confusion :+1:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.