Add else if to ask more questions in a row, and see that the first true one wins, so their order sets the ranges.
A spirit level shows whether a shelf is flat, tilted left or tilted right. One reading, three possible answers, and exactly one of them shows.
if … else chooses between two things. For three or more, click the + on an if block again: it adds else if, another question. The micro:bit asks the questions from the top.
Tilting left makes acceleration x go below 0; tilting right makes it go above 0. A small tilt gives a small number.
Make your prediction first. Help opens once you've locked it in.

basic.forever(function () {
if (input.acceleration(Dimension.X) < -300) {
basic.showArrow(ArrowNames.West)
} else if (input.acceleration(Dimension.X) > 300) {
basic.showArrow(ArrowNames.East)
} else {
basic.showIcon(IconNames.SmallSquare)
}
})
Read the questions from the top, with -100 in mind.
Move the mouse over the micro:bit to tilt it. Try a small tilt and a big tilt, left and right.

basic.forever(function () {
if (input.acceleration(Dimension.X) < -300) {
basic.showArrow(ArrowNames.West)
} else if (input.acceleration(Dimension.X) > 300) {
basic.showArrow(ArrowNames.East)
} else {
basic.showIcon(IconNames.SmallSquare)
}
})

basic.forever(function () {
if (input.acceleration(Dimension.X) < -300) {
basic.showArrow(ArrowNames.West)
} else if (input.acceleration(Dimension.X) > 300) {
basic.showArrow(ArrowNames.East)
} else {
basic.showIcon(IconNames.SmallSquare)
}
})
Work out what shows for each reading.
Leo's program:

basic.forever(function () {
if (input.acceleration(Dimension.X) > 0) {
basic.showIcon(IconNames.SmallDiamond)
} else if (input.acceleration(Dimension.X) > 500) {
basic.showArrow(ArrowNames.East)
} else {
basic.showIcon(IconNames.SmallSquare)
}
})
For each value of acceleration x, what shows?
| acceleration x | shows |
|---|---|
| -500 | |
| 0 | |
| 400 | |
| 300 |
Leo's program is in the editor. Swap the questions so both parts can be reached.
Swap the two questions: > 500 first, then > 0.
Drag the arrow into the first part and the diamond into the else if part.
Add another else if for a big tilt left.
Click + to add another else if, above the else.
Use < -500 for a big tilt left, and show a left arrow.
Fix Leo's tilt: a big tilt right shows the arrow, a small tilt right shows the diamond.
This ticks by itself when your blocks do what is asked.
Add a big tilt left (below -500): a left arrow.
This ticks by itself when your blocks do what is asked.

basic.forever(function () {
if (input.lightLevel() < 50) {
basic.showLeds(`
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
`)
} else {
basic.showIcon(IconNames.SmallSquare)
}
})
This is last lesson's bike light. What does it show at each light level?
| light level | shows |
|---|---|
| 30 | |
| 200 |
Make a comfort meter for a classroom, in one if block with three parts:
You need only two questions. The order does the rest.
One if block with an else if and an else. You need only two questions.
Ask < 15 first, then < 25. Anything under 15 was already caught by the first question.
A comfort meter: cold below 15, just right from 15 to 24, hot from 25, in one if … else if … else.
This ticks by itself when your blocks do what is asked.
This spirit level points the way to tilt back to flat, and shows a tick when it is level. Make it fussier (a smaller tilt counts as not level), then make it check forward and back as well.
Students add else if to ask more questions in a row, and see that the first true question wins, so the order of the questions sets the ranges. About 40 minutes.
Open the teacher guide: answers, solutions, slides and a worksheet.
Click the + at the bottom of an if block to add else if (another question). The micro:bit asks the questions from the top; the first true one runs and the rest are skipped. else runs only when every question above it is false. That makes ranges simple: temperature < 15, then else if temperature < 25 means 15 to 24, because anything under 15 was already caught. It also makes order matter: ask > 0 before > 500 and the second can never run. Tilt in the simulator: move the mouse over the micro:bit.
Seeing that only the first true question counts. Ask them to read the questions from the top with one value and stop at the first yes.
Stretch: Make the comfort meter show five ranges (freezing, cold, right, warm, hot) with four questions.
Support: Give students the if … else if … else already in forever with the pictures in, and ask them only to fill in the two questions.
Next unit: lists, which keep many values under one name. Class ideas: a tilt game where players hold the micro:bit level for ten seconds; a comfort meter by each classroom window with real micro:bits.