If you're seeing this message, it means we're having trouble loading external resources for Khan Academy.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Logic and if Statements

1 project
1 article
6 challenges
6 talkthroughs
Teach your program to make decisions!

If Statements

Jessica introduces if statements, a way for your program to decide whether or not to execute a block of code.

More Mouse Interaction

Pamela explains how to use mouseIsPressed with if statements to execute code only when the user is pressing their mouse.

Booleans

Jessica introduces the idea of "booleans", values that can either be true or false.

Logical Operators

Pamela shows how to use different logical operators (like && and ||) inside if statements.

If/Else - Part 1

Jessica introduces if's soulmate: else.

If/Else - Part 2

Jessica shows how to make your conditionals more powerful with "if else".

Project: Magic 8-Ball

<p>In the logic challenges, you practiced if and else. Now, use that knowledge to program a magic 8-ball, so you can ask your programs for answers to all your deepest life questions.</p> <ol> <li>Change the <code>if()</code> so it checks ...