What are conditions in coding?
Well, conditions allow our program to check if there are certain situations present. If they are, then we have instructions for the computer to run. Generally, people call conditions "if,then,else" statements as they involve us using those terms. For example, let's say the situation our program is monitoring is the temperature in our house. We might write our conditions like this:
IF the temperature in our house is greater than 20 degrees Celsius,
THEN turn the heating off.
ELSE, turn the heating on.
When you think about it, we use conditions all of the time in our everyday lives. Try out the unplugged activity below that helps us understand the use of 'if’, ‘then’ and ‘else’ to run certain commands.
Try this out at home
You can call this out with family members in your home or you can play along yourself as you read each line.
1) Read out the following sentences. You should respond based on how the statement applies to you.
For example, with the sentence "If you love to code, then put your right hand in the air, else leave your hand down", I would put my right hand in the air!
(a) If your name begins with the letter 'C', then clap once, else clap twice.
(b) If your hair is brown, then point to your head, else put your finger on your chin.
(c) If the month of your birthday is January, February or March, then whistle, else click your fingers.
(d) If you have a pet at home, then do three bunny hops, else do three jumping jacks.
(e) If you have blue eyes, then shout ‘blue’, else if you have brown eyes, then shout ‘brown’, else shout ‘neither’.
(f) If you had toast with your breakfast, then stick out your tongue, else if you had cereal, then hold your right ear, else hold your left ear.
(g) If your name begins with a letter from ‘A’ to ‘H’, then raise your right hand, else if your name begins with a letter from ‘I’ to ‘Q’, then raise your left hand, else leave your hands on your lap.
(h) If your favourite hobby is to play sport, then jump in the air twice, else if your favourite hobby is playing a musical instrument, then pretend to play the guitar, else if your favourite hobby is reading, then hold your two hands out on front of you with your palms facing up, else put your two hands on your hips.
2) Now, can you create your own 'if, then, else' statements to test out on someone in your house? The above list might help you come up with some other conditions of your own.
Well, if you have done the above challenge, then you are all set for our third lesson on MakeCode with micro:bit. Here we go.
So, now that you have learned about creating a program that contains variables and conditions, can you complete the home challenge before moving onto the next lesson. The DreamSpace team have provided you with two different options to choose from:
Create An Accessible Dice: When a person shakes the micro:bit they should know what the number rolled is because of the LEDs (if hearing disability) or sounds (if sight disability). You will need to use variables and conditions like we did in lesson three.
Create An Exercise Picker: When you shake the micro:bit, it should pick an exercise at random for you to do at home. You can include strings, animations and music into this one too. Once again, you will need to use variables and conditions.
Download the PDF below to see some home challenge support guides including some planning sheets & starter blocks to help you get going!