Debug it with code

Find and fix the errors

At the time of writing in the UK, people are arguing and deciding whether to vote to stay in the European Union or vote to leave. The code below is broken (like the EU?) but is worth fixing (like the EU?).

Hold your own EU referendum using a micro:bit

Hold your own EU referendum using a micro:bit

When fixed it will let you have your own referendum by passing the micro:bit around the room for each person to press A or B. If you touch pin 0 for 3 seconds it will keep showing you the result of the vote, until you reset the micro:bit for another vote.

There are three deliberate errors:

A syntax error is stopping the code from running at all. You’ll see an error message telling you which line the error is on when you attempt to run the code. Compare that line with similar lines to see what’s missing.

runtime error doesn’t stop the code from running but does make it crash when it gets to a certain point in the code. Compare line 23 with 25, 27 and 29 and you’ll find a variable spelt incorrectly that causes a runtime error.

A logical error is making your code behave incorrectly: it does exactly what it’s told to do but its been told the wrong thing. See what happens when you vote for B and try to work out what’s gone wrong.

  • See if you can find and fix all three errors to make your own micro:vote counter: