Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

if statement problems

Is the above problem because I'm using = instead of === ?

cut - added answer as answer

3 Answers

Hi Jason,

= is an assignment operator. So basically, you stored the value 'yes' in the variable 'answer'.

== is a comparison operator which would check if the answer is equal to 'yes'. If you type 'no', your message saying you should stay at home will appear. If you type 'yes', "Let's go to the shops" will be displayed. So: == compares value, but it will return true even if the type differs (5 == '5' is true, even though one is a string while the other one isn't).

=== is also a comparison operator, but it's more strict than ==. This means that if you'd compare 5 to '5', for example, this would equal false, because those values are not strictly the same (one is a string while the other one isn't). So: === compares type and value.

I hope this helps! ✨

not sure what - cut - added answer as answer means

I originally replied by adding a comment instead of by posting an 'answer' - I just posted my answer, though. :) Sorry for the confusion!

oh ok, thanks for your response,

No problem!