CodeJavaScript + p5.js · ⌃ Space for hints
Draft saved locallyJavaScript · Spaces: 2
Live preview move your pointer inside
Comparisons Create Booleans
A comparison asks JavaScript a yes/no question and produces a Boolean (true or false).
let energy = 30;
let lowEnergy = energy < 50;Read energy < 50 as: “Is energy less than 50?” With energy at 30, the answer is true.
Useful comparison operators include:
<less than>greater than<=less than or equal to>=greater than or equal to===exactly equal
Best practice
Do not write lowEnergy = true just because it happens to be true for today’s value. Calculate it from energy so the answer stays correct when the data changes.
Learn more
01
Your mission
Make lowEnergy automatically become true whenever energy is less than 50.
- Make lowEnergy automatically become true whenever energy is less than 50.
Mission complete Run sketch