Pssst...use your keyboard arrows to turn the page!
Yo, coders! You’re about to learn how to do something kind of amazing: how to teach your programs to make decisions.
As human beings, you know how to make tons of decisions. Like, "IF something is hot, THEN don’t touch it". Or, "IF it’s raining, THEN use an umbrella". Or, "IF you’re hungry, THEN eat a taco".
Sadly, computer programs don’t know how to make any of these decisions. But thankfully, we can teach them how using if-then statements!
Every if-then statement looks exactly the same: it starts with the word “if”, followed by some statement, and finally the word “then” followed by some action. If this statement is true, then do some action.
We can see if-then statements in basically every app, game, or device we’ve ever used. For example: “IF the power button is pressed, THEN turn on the console.” And “IF the space key is pressed, THEN fire mah laser”, and “IF I touch the monster, THEN reduce my health”.
Now, take 30 seconds to think of as many if-then statements as you can with your class!
Notice that the action – like firing the laser, or turning on the tablet – is only done IF the first part is true.
That’s how computer programs make decisions – by deciding IF something is true or false using if-then statements.