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 trialKEVIN SINGH
682 Pointsexplanation of the question
Assuming that Sara has taken the Java and Python tracks, what is the value of isFamiliar below:
boolean isFamiliar = ( learnedJava || learnedPython || learnedRuby );
is said false and it was wrong answer why??
1 Answer
andren
28,558 PointsBecause the OR (||) operator will return true if any of the supplied conditions are true, since learnedPython and learnedJava are true it returns true. It would have returned true even if only one of those were true, it will only return false if all conditions are false.
You can basically read the condition in your example as:
Is learnedJava true? OR is learnedPython true? OR is learnedRuby true? If the answer to any of those questions is yes then it will immediately return true.
The AND (&&) operator works the opposite way, it will only return true if all conditions are true, and false if any single condition is false.
KEVIN SINGH
682 PointsKEVIN SINGH
682 Pointsthank you very much