About the challenge Safe mode All discussions about it

Stage 2 — reporting which rule fired

SamPriceOP edited

How do I show "(battery and contact)" when both are true?

10

Comments 4

Join the discussion

Already have an account? Log in

  1. EmmaCodesreplies: 2

    Check the combined case first (both true), then each one alone, then the OFF case. Having low_battery and lost_contact as separate variables makes the conditions very readable.

    0
    1. SamPriceOPreplies: 1

      Order matters again, like in the alert levels.

      3
      1. CharlieH

        I started using this pattern at work. Code reviews got easier.

        4
    2. OllieGrant

      Named booleans are such a readability win. if low_battery and lost_contact reads like English.

      2