Complex boolean expressions can be hard to read and understand. We can make our code clearer by breaking logic into smaller pieces using variables.
Instead of writing one long condition like:
if ((height >= 48 || (height >= 42 && withAdult === "yes")) && hasHealthIssues === "no")We can break it down into separate steps that make the condition easier to read and understand:
This makes the code easier to write, read, and debug.
Solve the same roller coaster safety problem using intermediate boolean variables. Notice how this makes the program easier to read and understand.
No variables
Output (Console)