Basic JavaScript - Use Conditional Logic with If Statements

I have checked this code against the solution and cant for the life of me find any difference in the two. It says that it returns correctly for a true condition but not for a false one. Please help, is this a bug or am I being stupid and have left out some little detail?

  **Your code so far**
function trueOrFalse(wasThatTrue) {
// Only change code below this line
if (wasThatTrue = true){
  return "Yes, that was true";
}
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/104.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Use Conditional Logic with If Statements

Link to the challenge:

Here you are setting wasThatTrue equal to the boolean value true. You should instead use the comparison operator === (though, you could also omit this check).

3 Likes

oooooh thank god!!!
That worked, they havent covered that in the course yet. Thanks so much!

The example doesn’t use = or === at all:

function test (myCondition) {
 if (myCondition) {
   return "It was true";
 }
 return "It was false";
}

Hey there,
My brother had the same problem to wrap around his head with operators.
using one β€˜=’ you assign whatever you write next.

You are basically saying almost the same as you would write:
function trueOrFalse(wasThatTrue) {
return true;
}

As Jeremy mentioned, you are not comparing, you would need to use β€˜==’ or β€˜===’ to compare.