IF, THEN, ELSE

Or how to make a game in Excel without even trying...
Learning the logic of IF, THEN, ELSE statements is a crucial step in programming, mathematics, game design, and creating simulations or models.
In this lesson you will create a game for first grade students that will help them with their arithmetic or spelling skills. Once we have created our games a class of first graders will come up and play your game - so it's important that it works!
Let's Get Started
Open Excel, save your file in your directory, and follow the directions below.
- Go to cell B2 and type the number 1. Type the number 2 in B3 and autofill down to 10.
- Go to C2 and type a simple first grade math problem. You can make it addition or subtraction. Now fill in C3 through C11 with more problems. They can be all addition or all subtraction or mixed.
- Put an = sign in cells D2 through D11
- Leave cells E2 through E11 blank. This is where the person playing the game will type in their answers.
- Now the magic begins! We need to tell the computer what face to show. If the answer is correct, put a Happy Face, but if it's not, put a Sad Face. A happy face happens to be a J in Wingdings font and the sad face is an L in the Wingdings font.
We do this with an
IF, THEN, ELSE statement.
- Begin in F2. Begin by typing an equal sign [=]. This lets Excel know that what follows is a formula.
- Here is the entire formula
=IF(E2=5,"J","L") - Here is what the formula says - If the player types a 5 into cell E2 then show a J, if it's anything else show an L.
Extension 1
What if we wanted no happy or sad face if the answer space was blank? In that case we need a nested If statement.
=IF(E2=5,"J",IF(E2="","","L"))
Here is what the formula says - If the player types a 5 into cell E2 then show a J, if it's blank then show nothing and if it's anything else show an L.
Extension 2
Conditional formatting
Go to format>conditional formatting to tell Excel that if a cell is showing a J then make it green and if it is showing an L then make it red.
Sharing
Now that you've completed your game. make it really nice with large text, colored fonts and then share it with someone in first grade :-).