CS111: Control Structures - Conditionals
Using if/else statements for game logic
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
ifstatements test boolean conditionselseprovides alternative branchelse ifchains 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