We’re going to be recreating the sorting hat from Harry Potter using Microsoft Block Editor. Go ahead and create a new project. First decide which Input function you’d like to use to display the Hogwarts Houses. I’ve used the A Button, but this will work with whatever Input method you like.
Create the following:
Click “Item” in Set “Item” and select New variable and name it RandomNumber. This variable will allow you to assign each of the Hogwarts Houses a number, along with pick random 0 to “4”, it’ll cycle through the various Hogwarts Houses you assign later.
We’re going to have to change the “4” to 3 because we have four Hogwarts Houses. Sounds a little silly, why 3?! Well 0 counts too!
If you press the Gear icon on if do it’ll have a little popup. In this popup you can add more to the if do without creating entire new sections. Drag the else if into the if, do this three times. Click the Gear to remove the popup once you are finished.
You’ll need to either duplicate (saves lots of time!) or recreate the RandomNumber = “0” and add them to else if. Change each of the numbers on the end going from 0 to 3. Same with the show string “Ravenclaw”.
You can compile and upload it your BBC micro:bit and find out which house you’re in!