This problem is actually logic-related; similar to questions related to software programming. If you'll learn to love Math like I do, you will not only love programming but find it very easy in terms of logically writing your script/code.
Foremost, ask your teacher what output is expected if both conditions were true, that is if both e and f both have values, what should h output?