Basic JavaScript - Use Conditional Logic with If Statements

Tell us what’s happening:
Describe your issue in detail here.

My error says that my 'wasThatTrue; function doesn’t return correctly when the argument is false. :thinking:

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/116.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Use Conditional Logic with If Statements

Link to the challenge:

This line doesn’t do what you think it does…

2 Likes

Thank you so much.
I realize now that it should have been == :smiley:.
Such a small error caused me so much stress :joy:

Really, you want ===

== can be confusing in its behavior!

1 Like

But it passed when I did ==. What’s the difference?

The next few challenges will talk about this.

Really, you didn’t need to use === or == since wasThatTrue will either be true or false (or truthy or falsy)

1 Like

Mod Edit: SOLUTION REMOVED

== and === are both used for comparison but they behave differently eg:

== is used to check equality of values after performing type coercion if the operands have diiferent types.
Type coercion means javascript will attempt to convert one or both operands to a common type before making the comparison.

If the values are of different types, JavaScript will try to convert them to a common type and then compare them.

eg:
1 == '1'; // true
true == 1; // true

will return true because JavaScript converts the string '1' to the number 1 before comparing them.

=== (Strict Equality Operator):

The other ones is called the Strict Equality Operator

=== operator, checks for both value and type equality.
It does not perform type coercion, so if the operands have different types, it returns false .

1 === '1'; // false
true === 1; // false

2 Likes

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

2 Likes

Thank you so much. You explained that really well and I think I got it now :smile:!

1 Like

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