Skip to content
Your progress

Checking your sign-in…

Who's learning?

Each profile keeps its own read lessons, badges, streak, and practice scores on this device.

Lesson 10 of 11

8 min

Text size

Keep this table open beside the editor while you answer.

Eight lines that turn a week of readings into totals, means and a chart
IdeaThe line to keep
A row of valuesA list holds many values, in order, under one name. Ask .length for the count — 0 for an empty list.
Reaching one of themEvery item has a position, starting at 0. The last one sits at .length - 1. In this editor, asking past the end stops the run. The message names both numbers. Other languages may hand back a blank value instead.
Building it up.push() adds one value to the end of a list. So a program can build a list while it runs. Where the empty list is made decides what ends up in it.
Adding them all upOne box sits outside the loop. One line inside it adds each item on. That pair turns a whole list into one total.
The mean in codeThe mean is the total divided by the count. Written as a function, it works on any list you hand it. Longer or shorter, the lines do not change.
Biggest and smallestWalk the list once, carrying the best so far. The biggest is found, and nothing is put in order. Start the best box at the first item. Then compare every item against it.
Counting into groupsA tally is a list of counts, one per group. It is built one add at a time. A group with nothing in it still gets a row. That row says 0.
Drawing it from the listThe bars are drawn from the numbers the program printed. Change the data, and the picture follows. The picture was always just those numbers.

What does .length give for an empty list?

  • Nothing. An empty list has no length.
  • 1
  • 0

A list holds 7 readings. Where does the last one sit?

  • Position 6
  • Position 7
  • Position 1

rain holds 6, 46, 2. What does rain[1] give?

  • 6
  • 46
  • 2

In this editor, a program asks a 5-item list for position 5. What happens?

  • It gives back 0 and the run goes on.
  • It gives back the last item in the list.
  • The run stops. It names 5 and 5.

What does .push() do to a list?

  • It adds one value to the end.
  • It removes the last item.
  • It puts the items in order.

let meals = []; sits inside the loop. What is left at the end?

  • All six counts, in register order
  • One entry, the last count
  • An empty list, with nothing in it

Where does the total box belong in an adding loop?

  • Inside the loop, on the first line
  • After the loop
  • Before the loop

A list totals 70 across 7 readings. What is the mean?

  • 10
  • 7
  • 63

Six days total 66, so the mean is 11. A seventh day of 4 joins. What happens to the mean?

  • It rises.
  • It falls to 10.
  • It stays at 11.

A week totals 69 across 7 days. What does the machine print for the mean?

  • 10
  • 9.9
  • 9.857142857142858

A list holds temperatures, all below 0. Where should the best box start?

  • At the first item
  • At 0, as with weights
  • At the last item in the list

7A was on a trip, so no slip says 7A. What does the tally show for 7A?

  • No row
  • A row that says 0
  • A row that says nothing

A tally has the counts 5, 3, 0, 4, 3, 3. What do they add up to?

  • 15
  • 21
  • 18

One bar on the chart is too tall. Where do you fix it?

  • In the data
  • In the picture
  • In the label

.length is 7. What is 7 in this list?

  • The last position in the list
  • The count of items
  • The first position in the list

That is the track: a list, a loop, and some numbers.

Next: How AI Learns I: From Rules to Data.

Reveal every answer to finish this lesson.