If statements are used to perform an action when a condition is true. Imagine we are trying to decide if we need an umbrella.

Ask for the weather if (It is raining) { Bring an umbrella }

An if statement has the following format:

If (condition) { Action to perform if the condition is met }

We define a condition, and code to run if that condition is met. When the condition is met, it is evaluated as true, when not, it is false. When the condition is false, the code in the brackets is not run. The previous example allows us to bring an umbrella when it is raining, and bring nothing when it is not.

Let’s practice using an if statement to reach the flag.


Codey needs to do one action before getting the key, then to go to the door. Can you define a program that gets Codey to the door after getting the key?


Codey needs to go up if they don’t have the key.

While program is running If Codey does not have the key Move Up Move Right

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?