What are we going to do?
- Understand what variables are and why and when to use them in a program.
- Learn how to create a variable, set the variable to an initial value, and change the value of the variable within a micro:bit program.
- Learn how to create meaningful and understandable variable names.
- Understand that a variable holds one value at a time.
- Understand that when you update or change the value held by a variable, the new value replaces the previous value.
In order to learn that, we are going to use our humbot mi:pet to keep score when playing Rock, Paper, Scissors.
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:
- Change the A and B player names to match your initials
- Extra challenge.There is more we can do with the input we received using this program. With maths functions you can do some operations. You can find these operations under the maths section of the toolbox. With that in mind, are you able to show the total number of ‘rounds’ that were played? To do this, we can add the values stored in the variables we created to keep track of how many times each player won and how many times they tied. (You can find the solution here but don't use it unless it's completely necessary, try to do it by yourself first)
If you managed to finish this activities, you can search for more challenges on micro:bit's website