Exercise 5 - If Functions
Exercise 5 - If Functions
The IF function can be used to decide what text to display (‘Correct’ or ‘Incorrect’). We’ll start with a simple solution
and then look for ways to improve on it. You may use Excel or Google Sheets for this task.
b. Name the worksheet ‘Multiply’ and save. For the moment, the spreadsheet doesn’t do anything.
– The IF Function
The IF function allows us to display different values or text in a cell depending on some condition. In our case, we
want to ask a question then display the comment ‘Correct’ if the answer entered is correct, or ‘Incorrect’ if it is not.
The IF function works as follows:
= IF ( F8 = B8 * D8 , "Correct" , "Incorrect" )
1. Display Instructions?
At the moment, our three instructions are always visible. We can decide whether to display each instruction
depending on whether each box has something in it or not. Use a pair of double quotes to mean empty.
2. ELSE IF
You may have used the term ‘ELSE IF’ when considering algorithms before. The problem with our spreadsheet is
that it displays the word ‘Correct’ or ‘Incorrect’ even when the answer box is blank. It would be better to have
no words displayed until there is an answer in place.
Try out this formula in cell G8. No word should be shown unless you enter an answer.
3. OR (a Conditional Operator)
This is getting tricky now, but if you’re a real expert, you
can add a number of conditions inside a bracket with a
conditional operator. Use this method to only display a
word if all three boxes have been filled. Separate your
conditions with commas.