What are we going to do?
Computer programs are instructions telling the computer how to process input and deliver output. An important part of programming is telling the computer WHEN to perform a certain task. For this, we use something called ‘conditionals’. Conditionals get their name because a certain Condition or Rule has to be met.
For example, have you ever had your parents say..?
- “If you clean your room, you can go out with your friends.”
- “If your homework is done, you can play video games.”
- “If you do your chores all week, you get your allowance, else you are grounded.”
These are all conditionals! Conditionals follow the format of IF this, THEN that.
Objectives of this activity
- Understand what conditional statements are, and why and when to use them in a program.
- Learn how to use the Logic blocks ‘If…then’ and ‘If…then…else’.
- Practice using the Logic blocks so different conditions yield specified outcomes.
- Demonstrate understanding and apply skill by collaborating with classmates to create a game that uses a micro:bit and a program that correctly and effectively uses conditionals.
At the end, we will play Rock, Paper, Scissors against our mi:pet, let's try to beat him!!
Now it's your turn!
It was about time to let you try it for yourself! I now propose some challenges that I encourage you to do. I think they are fun and I trust you can pass them!
Remember that each time you change the program by adding or removing some blocks, you can see how it looks at the left side of the editor. When you're happy with the result, you'll have to download it again and send it to micro:bit board following same steps as before.
Here you have some challenges:
- Mod the game to use different images or to add more options like ‘Rock Paper Scissors Lizard Spock’
- Extra challenge. Are you able to keep score of both your wins (mi:pet and yours)? Tip: remember last activity
If you managed to finish this activities, you can search for more challenges on micro:bit's website