For this challenge you will design and write a program to play against the BBC micro:bit.
The micro:bit will display a random number between 0 and 100. It will then ask the end-user whether they believe the next number will be higher or lower. The program will then generate the next number. If the user guessed right (e.g. the next number is higher or lower than the previous one) then the user scores one point. The game stops when the user guesses it wrong.
Learning Objectives
By completing this challenge you are going to use selection (IF statements) and comparison operators such as >= or <= to compare numbers. You will also use variables to store the value of random numbers, and to keep and increment a score as the game progresses.
Solution
Try to implement the game by yourself on the BBC micro:bit website:
If you are stuck you can always use our solution below:
Extension Task:
That’s it you have a fully working game. We can tweak it slightly though. For instance how could we code the micro:bit so that when the user presses both the A and B buttons at the same time, the game restarts from the beginning – a new set of numbers is generated and the score is reset to zero?