BBC micro:bit – Hogwarts Sorting Hat

hogwarts-sorting-hatIn the Harry Potter series of novels written by British author J. K. Rowling, The Sorting Hat is a magical hat at Hogwarts that determines which of the four school Houses each new student belongs most to. These four Houses are Gryffindor, Hufflepuff, Ravenclaw, and Slytherin.

In this challenge we are going to write a program for the BBC micro:bit to act as the sorting hat. Whenever a students from Hogwarts school of Witchcraft and Wizardry will shake the BBC micro:bit, a message will appear telling them which house they belong in.

You will need to use the micro:bit website to create the code using the JavaScript Block Editor.


Block Programming

Here is the code to implement the Sorting Hat algorithm:

Resetting the Sorting Hat

Add the following code to reset the Sorting Hat when either button A or button B is pressed:

Did you like this challenge?

Click on a star to rate it!

Average rating 3.6 / 5. Vote count: 90

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: ,