We make decisions every day based on certain conditions.

Is the alarm ringing? If so, turn it off. Is it raining? If so, bring an umbrella. Is the ice cream truck parked outside? If so, it’s time for a treat.

We can also implement this decision-making ability in our programs using conditionals. Conditionals check on values and, depending on their status (if the values turn out to be true or false), executes an appropriate block of code in response.

In this lesson we’ll cover:

  • if, else if, and else statements.
  • comparison operators.
  • logical operators.
  • the switch statement.
  • short declarations in conditionals.
  • how to use conditionals in randomized conditions.

If you’re ready, Go on to the next exercise. Else, come back when you’re ready!


Are you thinking about moving on to the next exercise? What conditions are you waiting for?

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?