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 trialMonika Kesarwani
5,851 Pointscan anybody explain me. What this code explaining here. I can not understand. Thank you so much in advance
What does the following statement evaluate to? (!true || !false) && (true && !false)
2 Answers
Jennifer Nordell
Treehouse TeacherHi there, Monika Kesarwani ! Let's break this down a bit into bite-sized chunks. But before we proceed it's important to understand the difference between AND and OR. In an AND statement, both parts must be true for the entire thing to be true. In an OR statement, both may be true, but at least one must be true for the whole thing to be true.
So we start with this:
(!true || !false) && (true && !false)
Now the !
means to reverse the truthiness of that so !true
becomes false
and !false
becomes true
. Much like we do with arithmetic, we do the things in parentheses first. Let's start by looking for anything with a ! and reverse its truthiness in place.
(!true || !false) && (true && !false)
// after looking for ! and reversing truthiness
(false || true) && (true && true)
Ok so now that we've gotten the ! out of there, we can start working on the evaluations inside the parentheses:
//The first parentheses contain an OR. Only one has to be true for it all to be true
(true) && (true && true)
// The second parentheses contain an AND. BOTH have to be true for it to be true (which they are)
(true) && (true)
// Now we're left with one AND statement and both are true
true && true
Thus, the evaluation of this is true
. In our last step, we had true AND true. If both are true, then the evaluation is true.
Hope this helps!
Heidi Puk Hermann
33,366 PointsThis one is a bit tricky, but it evaluates to "true".
You need to look at each consecutive part; So first you have:
(!true || !false)
- This statement reads "not true" OR "not false", meaning that it will always return "true".
(true && !false)
- This statement reads "true" AND "not false", meaning that it will return "true"
Since both statements return "true", the total statement is also "true".
Monika Kesarwani
5,851 Pointsthank you so much for great help
Monika Kesarwani
5,851 PointsMonika Kesarwani
5,851 Pointsthank you so much for you effort.