How to query Firebase (angfire) record using if-else condition

Please if someone is there to help me out on this question at stackoverflow. I have been trying alot of ways but can’t be done for me. Any help would be appreciated.

I also use this link to do, but can’t be solved:
https://firebase.google.com/docs/reference/android/com/google/firebase/database/Query

Link to my question: