Track quiz
Keep this table open beside the editor while you answer.
| Idea | The line to keep |
|---|---|
| A row of values | A list holds many values, in order, under one name. Ask .length for the count — 0 for an empty list. |
| Reaching one of them | Every 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 up | One 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 code | The 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 smallest | Walk 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 groups | A 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 list | The 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?
A list holds 7 readings. Where does the last one sit?
rain holds 6, 46, 2. What does rain[1] give?
In this editor, a program asks a 5-item list for position 5. What happens?
What does .push() do to a list?
let meals = []; sits inside the loop. What is left at the end?
Where does the total box belong in an adding loop?
A list totals 70 across 7 readings. What is the mean?
Six days total 66, so the mean is 11. A seventh day of 4 joins. What happens to the mean?
A week totals 69 across 7 days. What does the machine print for the mean?
A list holds temperatures, all below 0. Where should the best box start?
7A was on a trip, so no slip says 7A. What does the tally show for 7A?
A tally has the counts 5, 3, 0, 4, 3, 3. What do they add up to?
One bar on the chart is too tall. Where do you fix it?
.length is 7. What is 7 in this list?
That is the track: a list, a loop, and some numbers.
Next: How AI Learns I: From Rules to Data.