hasKey asks a yes/no question.
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.
if (hasKey) checks the answer.{ } runs only when true.Does the explorer have the key?
let hasKey = true;
if (hasKey) {
openDoor();
}
Choose true or false, then run the code.
Waiting for condition...
Test trueTest false
An if statement runs its action only when the condition is true.
Both decisions tested!
You changed one boolean variable and watched the same if statement make two different decisions.
Completed! Open If / Then Builder
