← Reference

Lists: cheat sheet

micro:bit Foundations · Find each block in the MakeCode toolbox (the category is at the end of each line).

list

Many values in order under one name. Places start at 0. Advanced › Arrays.

let answers = ["Yes", "No"]
The block

length of list

How many items are in the list. The last place is the length − 1. Arrays.

answers.length
The block

pick from list

A random place from 0 to length − 1 reaches every item, however long the list grows.

basic.showString(list[randint(0, list.length - 1)])
The block

get value at

The item at a place in the list, counted from 0. Arrays.

answers[0]
The block

pick random

A random whole number from the first to the second, both included. Math.

randint(0, 10)
The block

shared code

Send a place number; both micro:bits must hold the same list in the same order.

let words = ["Hi", "Yes", "No"]
radio.onReceivedNumber(function (receivedNumber) {
    basic.showString(words[receivedNumber])
})
The block