Welcome to the thirty-second of Altitude Foundation’s #MicroChallenges2020
Today’s challenge will revise conditional statements and explore Boolean logic – and win a micro:bit!
What’s a Micro Challenge?
These challenges are short activities to help you develop, revise or refresh your coding skills, posted every Monday, Wednesday and Friday.
Micro Challenge #32
Today’s challenge is to consider different uses for Boolean operators. In programming, Boolean logic can be described simply as TRUE/FALSE statements – Booleans are used to determine whether data is “true” (it meets the conditions laid out by the programme) or “false” (it doesn’t meet those conditions).
An easy way of describing this is by imagining you are flipping two coins. Let’s say you flip the coins 6 times and get the following results:
- HEADS / TAILS
- TAILS / HEADS
- HEADS / HEADS
- TAILS /HEADS
- TAILS / TAILS
- TAILS / TAILS
You now want to use Booleans to determine how many times the coins showed HEADS. This could be written as:
If (COIN 1 = HEADS) OR (COIN 2 = HEADS) add to count
If (COIN 1 = TAILS) AND (COIN 2 = TAILS) ignore
The first statement is our TRUE statement and the second is our FALSE statement. The bit in parentheses ex. (COIN 1 = HEADS) is the condition that has to be met. Multiple conditions can be combined within one Conditional Statement (for example, we are including two conditions in each Conditional Statement).
Booleans use conditionals (IF/THEN/ELSE IF), so it is useful to review that.
Booleans also use algebraic expressions, for example:
- equal to (=);
- greater than (<);
- less than (>)
- does not equal (<>)
Today’s challenge is to create an algorithm or pseudocode which uses Booleans to allocate points in a game. You will have to decide:
- The rules of your game – for example, a game where catching apples in a basket gains you points, or where you earn points by hitting certain objects with a ping pong ball.
- What conditions have to be met to score points
- What combination of conditions might means points are discounted and disqualified
- Does your pseudocode/algorithm ensure that points can only be scored in one way (i.e. have you ensured that your conditional statements don’t overlap or miss an opportunity to score)?
- Could you programme a game which uses Boolean operators using MakeCode for the MicroBit?
Win a micro:bit!
If you submit your response to this challenge via the Share It options below before the 30th of June, you will be entered into a prize draw for one of 5 micro:bits.
- The giveaway is open to any young person aged between 14 and 18 based in the UK.
We would love to see what you have created! Please send any pictures, videos, or files of your activities to us – either via Facebook, Twitter or Instagram using #MicroChallenges2020 or to email@example.com. If you are emailing them to us, please let us know if you are happy for us to share your stuff on our social media platforms (with credit, of course).
Sign-up here to receive a weekly email with Micro Challenges top tips and solutions: