Back to Variable Challenge
Code Studio · Level 3

Treasure Door Decision

Give JavaScript a brain. Set one true-or-false variable, then let an if statement decide whether the cave door opens.

Mission: Test both outcomes. Open the door with the key, then prove it stays locked without one.
1. CONDITIONhasKey asks a yes/no question.
2. CHECKif (hasKey) checks the answer.
3. ACTIONThe code inside { } runs only when true.
Choose the variable

Does the explorer have the key?

let hasKey = true;

if (hasKey) {
  openDoor();
}
Cave Door

Choose true or false, then run the code.

Magic key Closed cave door
Waiting for condition...
Test trueTest false

An if statement runs its action only when the condition is true.