...

Exercise: Roller Coaster Safety 2

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:

  1. Check if tall enough to ride alone (height >= 48)
  2. Check if tall enough with adult supervision (height >= 42 && withAdult === "yes")
  3. Combine the height checks (1 OR 2)
  4. Check final eligibility including health

This makes the code easier to write, read, and debug.

Your Task

Solve the same roller coaster safety problem using intermediate boolean variables. Notice how this makes the program easier to read and understand.

Variables

No variables

Loading...

Output (Console)