← Teacher guide

Lists

Students keep many values in one list and take one out by its place, counted from 0.

micro:bit Foundations · Lists · about 40 minutes · Open the student lesson

Classroom resources

Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.

Students will be able to

Timing

Predict and Run 7 min · Investigate 10 min · Modify 8 min · Mix it up 3 min · Make 9 min · Lunch menu 3 min

Before class

A list (MakeCode calls it an array, in Advanced › Arrays) holds many values in order under one name. Each item has a place (an index), counted from 0: in Yes, No, Maybe, Yes is at place 0. So a list of 3 has places 0, 1 and 2, and the last place is one less than the number of items. get value at takes out the item at a place. Picking at random is next lesson.

Running the lesson

  1. Predict: most students say Yes. Ask: which place does the micro:bit start counting from? Or: where does a ruler start?
  2. Run: No. Say it plainly: lists count from 0, like a ruler starts at 0.
  3. Investigate: the last-place question is where counting from 0 bites.
  4. Modify: adding Later and asking for place 3 makes students count.
  5. Mix it up: a tilt meter from the Decide unit, read from the top.
  6. Make: the chooser uses a variable as the place, and an if to go back to 0.

In class

On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.

The hard part (on purpose)

Counting places from 0. Ask them to point at each item and count aloud from zero.

When students get stuck

What you will seeA question to askThe fix
The list block has only one or two places.Where is the + on the list block?Click + on the list block to add places.
The chooser shows nothing after the third press.What is choice after three presses, and is there a place with that number?There is no place 3. When choice reaches 3, set it back to 0.
A number shows instead of the word.Is it show string or show number?Words need show string, from Basic.

Answers to the checks

  1. Predict: You press A. What does the micro:bit show?
    No. The places are counted from 0: Yes is at 0, No is at 1, Maybe is at 2. Place 1 is No.
  2. Places: The list is Yes, No, Maybe. What is at each place?
    Yes, No, Maybe
    The first item is at place 0. Three items use places 0, 1 and 2.
  3. The last place: A list has 5 items. What is the place number of the last one?
    4
    Places start at 0, so 5 items use places 0, 1, 2, 3 and 4. The last place is one less than the number of items.
  4. Jo's first word: Jo wants A to show the first word, Yes. She uses get value at 1. What does A show?
    No
    Place 1 is the second item, No. The first item is at place 0.
  5. Mix it up: A tilt meter: what shows for each value of acceleration x?
    right arrow, small diamond, small square
    600 is more than 500, so the first part runs. 200 is not, but it is more than 0. -50 is neither, so else runs.

Solutions

One possible solution for each task. Other correct programs are fine.

Modify › One more word

The program as blocks
Show as code
let answers = ["Yes", "No", "Maybe", "Later"]
input.onButtonPressed(Button.A, function () {
    basic.showString(answers[1])
})
input.onButtonPressed(Button.B, function () {
    basic.showString(answers[3])
})

Modify › The first word

The program as blocks
Show as code
let answers = ["Yes", "No", "Maybe", "Later"]
input.onButtonPressed(Button.A, function () {
    basic.showString(answers[1])
})
input.onButtonPressed(Button.B, function () {
    basic.showString(answers[3])
})
input.onButtonPressed(Button.AB, function () {
    basic.showString(answers[0])
})

Make

The program as blocks
Show as code
let moods = ["Happy", "Tired", "Hungry"]
let choice = 0
input.onButtonPressed(Button.A, function () {
    choice += 1
    if (choice == 3) {
        choice = 0
    }
    basic.showString(moods[choice])
})

Change a lunch menu

Open task: any program that does what the step asks.

Stretch and support

Stretch: Make B step backwards through the moods, going round to the last one after the first.

Support: Give students the A event with change and show already in, and ask them only to add the if that goes back to 0.

Exit ticket

A list has Red, Green, Blue. What is at place 2, and what is at place 3?

Blue is at place 2. There is no place 3: three items use places 0, 1 and 2.

What each step is for

Where it leads

Next lesson: pick an item at random, however long the list is. Class idea: a list of the week's homework, one item per day.