The big picture
One list, one loop. Every number here was worked out from them.
| Idea | Remember | Example |
|---|---|---|
| A row of values | .length counts a list. 0 for an empty one. | 7 readings, 7 |
| Reaching one of them | Positions start at 0. Last is .length - 1. | week[4] is Friday |
| Building it up | .push() adds one value to the end. | meals grows to 6 |
| Adding them all up | A total box outside the loop. | 0 → 28 → 59 → … → 166 |
| The mean in code | Total ÷ count, as a function. | 70 ÷ 7 = 10 |
| Biggest and smallest | Walk once, keep the best so far. | 78 is the heaviest |
| Counting into groups | A tally list, one slot per group. | 5, 3, 0, 4, 3, 3 |
| Drawing it from the list | Bars are the printed counts. | 4 cells for tomato |
Two numbers came up again and again. One is the count: .length, the loop's turns, the mean's divisor. The divisor is the number you divide by. The other is the position. The first position is 0 and the last is .length - 1.
Now the program does by machine what you once did on paper.