Beacon's Plant Status screen works. Every row shows its water level, and Lena loves it.
Comet is already restless. "Now Beacon should warn us when the tomatoes need water. Easy. Just warn when it is low."
Wren points at two readings on the screen. "What do you notice? Row 2 says 25. Row 5 says 60. Which one is low?"
"Row 2, obviously," Comet says. "But how does Beacon know that?"
Nova hovers between the numbers. "Would you like a hint?" she asks. "Every warning starts with a question that has only two possible answers."
Comet thinks. "Is the water level less than 30? Yes or no."
Wren smiles. "True or false," he corrects.
A Boolean value is either true or false. There is no third choice.
A comparison using a relational operator evaluates to a Boolean value.
So "Is the water level less than 30?" is a comparison, and its answer is true or false.
Beacon's alerts will all be built from comparisons like this one.
Relational operators compare two values. The table shows how each one is written in our pseudocode and how to read it aloud.
| Pseudocode | Read it aloud as |
|---|---|
| waterLevel = 30 | water level is equal to 30 |
| waterLevel ≠ 30 | water level is not equal to 30 |
| waterLevel > 30 | water level is greater than 30 |
| waterLevel < 30 | water level is less than 30 |
| waterLevel ≥ 30 | water level is at least 30 |
| waterLevel ≤ 30 | water level is at most 30 |
Suppose waterLevel holds 25 and lightLevel holds 80. Use these four conditions for the next questions.
C1: waterLevel < 30 C2: waterLevel ≥ 30 C3: lightLevel = 80 C4: lightLevel > 80
| Statement | True or false? |
|---|---|
| A Boolean value is either true or false. | ? |
| A comparison evaluates to a Boolean value. | ? |
| Is at least 30 is true when the reading is exactly 30. | ? |
| Is greater than 30 is true when the reading is exactly 30. | ? |
| A Boolean can also be maybe. | ? |
Strong start, developer. Tomorrow Beacon starts making real decisions with IF.