Conditionals (if/else)

Objective

Students must use conditional statements to make decisions based on game state and input.

Evidence

Multiple conditional branches for game logic:

  • Ghost.js - Conditional OR logic for state checking
  • Ghost.js - If/else collision distance checks
  • DeathBarrier.js - Multi-level conditional blocks

Implementation Details

  • if statements test boolean conditions
  • else provides alternative branch
  • else if chains multiple conditions
  • Conditions evaluate player state, collision, input
  • Boolean expressions control game flow

Key Concepts

  • Boolean expressions and truthiness
  • Comparison operators (===, !==, <, >, <=, >=)
  • Logical operators (&&,   , !)
  • Nested conditionals
  • Early returns to reduce nesting